Coverage for appr/exception.py: 84%

# Coverage for appr/exception.py : 84%

## 62 statements 52 run 10 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | from __future__ import absolute_import, division, print_function class ApprException(Exception): status_code = 500 errorcode = "internal-error" def __init__(self, message, payload=None): super(ApprException, self).__init__() self.payload = dict(payload or ()) self.message = message def to_dict(self): return {"code": self.errorcode, "message": self.message, "details": self.payload} def __str__(self): return self.message class InvalidUsage(ApprException): status_code = 400 errorcode = "invalid-usage" class InvalidRelease(ApprException): status_code = 422 errorcode = "invalid-release" class InvalidParams(ApprException): status_code = 422 errorcode = "invalid-parameters" class PackageAlreadyExists(ApprException): status_code = 409 errorcode = "package-exists" class PackageNotFound(ApprException): status_code = 404 errorcode = "package-not-found" class ResourceNotFound(ApprException): status_code = 404 errorcode = "resource-not-found" class ChannelNotFound(ApprException): status_code = 404 errorcode = "channel-not-found" class Forbidden(ApprException): status_code = 403 errorcode = "forbidden" class PackageReleaseNotFound(ApprException): status_code = 404 errorcode = "package-release-not-found" class UnauthorizedAccess(ApprException): status_code = 401 errorcode = "unauthorized-access" class Unsupported(ApprException): status_code = 501 errorcode = "unsupported" class UnableToLockResource(ApprException): status_code = 409 errorcode = "resource-in-use" class InvalidVersion(ApprException): status_code = 422 errorcode = "invalid-version" class PackageVersionNotFound(ApprException): status_code = 404 errorcode = "package-version-not-found" def raise_package_not_found(package, release=None, media_type=None): raise PackageNotFound("package %s doesn't exist, v: %s, type: %s" % (package, str(release), str(media_type)), {'package': package, 'release': release, 'media_type': media_type}) def raise_channel_not_found(package, channel=None, release=None): if channel is None: raise ChannelNotFound("No channel found for package '%s'" % (package), { 'package': package}) else: raise ChannelNotFound("Channel '%s' doesn't exist for package '%s'" % (channel, package), { 'channel': channel, 'package': package, 'release': release}) def raise_package_exists(package, release, media_type): raise PackageAlreadyExists("%s - %s - %s exists already " % (package, release, media_type), { "package": package, "release": release, "media_type": media_type})