diff --git a/lib/rapi/client.py b/lib/rapi/client.py
index c672d8aaef5a3b452f6295c09b7f00359a8ef3a1..b0745aabf4439808368aad30709643f69b030438 100644
--- a/lib/rapi/client.py
+++ b/lib/rapi/client.py
@@ -74,7 +74,9 @@ class GanetiApiError(Error):
   """Generic error raised from Ganeti API.
 
   """
-  pass
+  def __init__(self, msg, code=None):
+    Error.__init__(self, msg)
+    self.code = code
 
 
 class InvalidReplacementMode(Error):
@@ -414,7 +416,7 @@ class GanetiRapiClient(object):
       else:
         msg = str(response_content)
 
-      raise GanetiApiError(msg)
+      raise GanetiApiError(msg, code=resp.code)
 
     return response_content
 
diff --git a/test/ganeti.rapi.client_unittest.py b/test/ganeti.rapi.client_unittest.py
index abe3d3385f562fef46619e4d7748231a1ff02089..6089352ada296f450e004d5c09fec9f200c3f678 100755
--- a/test/ganeti.rapi.client_unittest.py
+++ b/test/ganeti.rapi.client_unittest.py
@@ -151,6 +151,15 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
   def assertDryRun(self):
     self.assertTrue(self.rapi.GetLastHandler().dryRun())
 
+  def testHttpError(self):
+    self.rapi.AddResponse(None, code=404)
+    try:
+      self.client.GetJobStatus(15140)
+    except client.GanetiApiError, err:
+      self.assertEqual(err.code, 404)
+    else:
+      self.fail("Didn't raise exception")
+
   def testGetVersion(self):
     self.client._version = None
     self.rapi.AddResponse("2")