#7 Throw appropriate exception in api requests
Merged 8 years ago by yangl1996. Opened 8 years ago by sayanchowdhury.
sayanchowdhury/libpagure master  into  master

@@ -0,0 +1,5 @@ 

+ # -*- coding: utf-8 -*-

+ 

+ 

+ class APIError(Exception):

+     pass

file modified
+3
@@ -4,6 +4,7 @@ 

  import requests

  import logging

  

+ from .exceptions import APIError

  

  class NullHandler(logging.Handler):

      # Null logger to avoid spurious messages
@@ -82,6 +83,8 @@ 

                  # TODO: use a dedicated error class

                  raise Exception(

                      'No output returned by %s' % req.url)

+             if 'error_code' in output:

+                 raise APIError(output['error'])

  

          return output

  

no initial comment