Skip to content

Commit

Permalink
Handle RequestEntityTooLarge error
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky committed May 7, 2023
1 parent 304106a commit cbd92cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions acoustid/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
ERROR_INSECURE_REQUEST = 16
ERROR_UNKNOWN_APPLICATION = 17
ERROR_FINGERPRINT_NOT_FOUND = 18
ERROR_REQUEST_TOO_LARGE = 19


class WebServiceError(Exception):
Expand Down Expand Up @@ -174,3 +175,12 @@ class FingerprintNotFoundError(WebServiceError):
def __init__(self):
message = 'fingerprint not found'
WebServiceError.__init__(self, ERROR_FINGERPRINT_NOT_FOUND, message)


class RequestTooLargeError(WebServiceError):

status = 413

def __init__(self):
message = 'request too large'
WebServiceError.__init__(self, ERROR_REQUEST_TOO_LARGE, message)
5 changes: 5 additions & 0 deletions acoustid/api/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from acoustid.ratelimiter import RateLimiter
from werkzeug.wrappers import Request, Response
from werkzeug.datastructures import MultiDict
from werkzeug.exceptions import HTTPException, RequestEntityTooLarge
from acoustid.utils import is_uuid, is_foreignid, check_demo_client_api_key
from acoustid.api import serialize_response, errors

Expand Down Expand Up @@ -191,6 +192,10 @@ def handle(self, req):
return self._ok(self._handle_internal(params), params.format)
except errors.WebServiceError:
raise
except RequestEntityTooLarge:
raise errors.RequestTooLargeError()
except HTTPException:
raise
except Exception:
logger.exception('Error while handling API request')
raise errors.InternalError()
Expand Down

0 comments on commit cbd92cb

Please sign in to comment.