From 0a28294d76c78dfb0c17e440aaa671860bef2008 Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Nov 03 2015 14:09:46 +0000 Subject: throw appropriate exception in api requests --- diff --git a/libpagure/exceptions.py b/libpagure/exceptions.py new file mode 100644 index 0000000..1402ce1 --- /dev/null +++ b/libpagure/exceptions.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + + +class APIError(Exception): + pass diff --git a/libpagure/libpagure.py b/libpagure/libpagure.py index 639b3fc..690521d 100644 --- a/libpagure/libpagure.py +++ b/libpagure/libpagure.py @@ -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 @@ class Pagure(object): # 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