mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
server/errors: add and document error codes
This commit is contained in:
@ -11,6 +11,7 @@ from szurubooru import api, middleware
|
||||
|
||||
def _map_error(ex, target_class, title):
|
||||
return target_class(
|
||||
name=type(ex).__name__,
|
||||
title=title,
|
||||
description=str(ex),
|
||||
extra_fields=getattr(ex, 'extra_fields', {}))
|
||||
@ -42,7 +43,11 @@ def _on_processing_error(ex):
|
||||
|
||||
def _on_stale_data_error(_ex):
|
||||
raise rest.errors.HttpConflict(
|
||||
'Someone else modified this in the meantime. Please try again.')
|
||||
name='IntegrityError',
|
||||
title='Integrity violation',
|
||||
description=(
|
||||
'Someone else modified this in the meantime. '
|
||||
'Please try again.'))
|
||||
|
||||
|
||||
def validate_config():
|
||||
|
@ -5,7 +5,7 @@ def verify_version(entity, context, field_name='version'):
|
||||
actual_version = context.get_param_as_int(field_name, required=True)
|
||||
expected_version = entity.version
|
||||
if actual_version != expected_version:
|
||||
raise errors.InvalidParameterError(
|
||||
raise errors.IntegrityError(
|
||||
'Someone else modified this in the meantime. ' +
|
||||
'Please try again.')
|
||||
|
||||
|
@ -103,6 +103,7 @@ def application(env, start_response):
|
||||
'%d %s' % (ex.code, ex.reason),
|
||||
[('content-type', 'application/json')])
|
||||
blob = {
|
||||
'name': ex.name,
|
||||
'title': ex.title,
|
||||
'description': ex.description,
|
||||
}
|
||||
|
@ -5,10 +5,15 @@ class BaseHttpError(RuntimeError):
|
||||
code = None
|
||||
reason = None
|
||||
|
||||
def __init__(self, description, title=None, extra_fields=None):
|
||||
def __init__(self, name, description, title=None, extra_fields=None):
|
||||
super().__init__()
|
||||
# error name for programmers
|
||||
self.name = name
|
||||
# error description for humans
|
||||
self.description = description
|
||||
# short title for humans
|
||||
self.title = title or self.reason
|
||||
# additional fields for programmers
|
||||
self.extra_fields = extra_fields
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user