Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add a NotFoundError exception in dashi

This exception can be serialized and raised on the client side.

Also move dashi exceptions to their own file.
  • Loading branch information...
commit 1292a6e6405dde0ed50de8a2b845cfb190b79f2d 1 parent 9e601cc
Pierre Riteau priteau authored

Showing 2 changed files with 35 additions and 31 deletions. Show diff stats Hide diff stats

  1. +4 31 dashi/__init__.py
  2. +31 0 dashi/exceptions.py
35 dashi/__init__.py
@@ -12,9 +12,11 @@
12 12 from kombu.entity import Queue, Exchange
13 13 from kombu.common import maybe_declare
14 14
  15 +from exceptions import DashiError, BadRequestError, NotFoundError, UnknownOperationError
15 16
16 17 log = logging.getLogger(__name__)
17 18
  19 +
18 20 class DashiConnection(object):
19 21
20 22 consumer_timeout = 1.0
@@ -356,35 +358,6 @@ def raise_error(error):
356 358
357 359 raise exc_cls(**error)
358 360
359   -
360   -class DashiError(Exception):
361   - def __init__(self, message=None, exc_type=None, value=None, traceback=None, **kwargs):
362   - self.exc_type = exc_type
363   - self.value = value
364   - self.traceback = traceback
365   -
366   - if message is None:
367   - if exc_type:
368   - if value:
369   - message = "%s: %s" % (exc_type, value)
370   - else:
371   - message = exc_type
372   - elif value:
373   - message = value
374   - else:
375   - message = ""
376   - if traceback:
377   - message += "\n" + str(traceback)
378   - super(DashiError, self).__init__(message)
379   -
380   -
381   -class BadRequestError(DashiError):
382   - pass
383   -
384   -
385   -class UnknownOperationError(DashiError):
386   - pass
387   -
388   -ERROR_PREFIX = "dashi."
389   -ERROR_TYPES = (BadRequestError, UnknownOperationError)
  361 +ERROR_PREFIX = "dashi.exceptions."
  362 +ERROR_TYPES = (BadRequestError, NotFoundError, UnknownOperationError)
390 363 ERROR_TYPE_MAP = dict((cls.__name__, cls) for cls in ERROR_TYPES)
31 dashi/exceptions.py
... ... @@ -0,0 +1,31 @@
  1 +class DashiError(Exception):
  2 + def __init__(self, message=None, exc_type=None, value=None, traceback=None, **kwargs):
  3 + self.exc_type = exc_type
  4 + self.value = value
  5 + self.traceback = traceback
  6 +
  7 + if message is None:
  8 + if exc_type:
  9 + if value:
  10 + message = "%s: %s" % (exc_type, value)
  11 + else:
  12 + message = exc_type
  13 + elif value:
  14 + message = value
  15 + else:
  16 + message = ""
  17 + if traceback:
  18 + message += "\n" + str(traceback)
  19 + super(DashiError, self).__init__(message)
  20 +
  21 +
  22 +class BadRequestError(DashiError):
  23 + pass
  24 +
  25 +
  26 +class NotFoundError(DashiError):
  27 + pass
  28 +
  29 +
  30 +class UnknownOperationError(DashiError):
  31 + pass

0 comments on commit 1292a6e

Please sign in to comment.
Something went wrong with that request. Please try again.