diff --git a/API.md b/API.md index ec5e4e8..9b79598 100644 --- a/API.md +++ b/API.md @@ -120,11 +120,58 @@ code together with JSON of following structure: ```json5 { + "name": "Name of the error, e.g. 'PostNotFoundError'", "title": "Generic title of error message, e.g. 'Not found'", "description": "Detailed description of what went wrong, e.g. 'User `rr-` not found." } ``` +List of possible error names: + +- `MissingRequiredFileError` +- `MissingRequiredParameterError` +- `InvalidParameterError` (when trying to pass text when integer is expected etc.) +- `IntegrityError` (race conditions when editing the same resource) +- `SearchError` +- `AuthError` +- `PostNotFoundError` +- `PostAlreadyFeaturedError` +- `PostAlreadyUploadedError` +- `InvalidPostIdError` +- `InvalidPostSafetyError` +- `InvalidPostSourceError` +- `InvalidPostContentError` +- `InvalidPostRelationError` +- `InvalidPostNoteError` +- `InvalidPostFlagError` +- `InvalidFavoriteTargetError` +- `InvalidCommentIdError` +- `CommentNotFoundError` +- `EmptyCommentTextError` +- `InvalidScoreTargetError` +- `InvalidScoreValueError` +- `TagCategoryNotFoundError` +- `TagCategoryAlreadyExistsError` +- `TagCategoryIsInUseError` +- `InvalidTagCategoryNameError` +- `InvalidTagCategoryColorError` +- `TagNotFoundError` +- `TagAlreadyExistsError` +- `TagIsInUseError` +- `InvalidTagNameError` +- `InvalidTagRelationError` +- `InvalidTagCategoryError` +- `InvalidTagDescriptionError` +- `UserNotFoundError` +- `UserAlreadyExistsError` +- `InvalidUserNameError` +- `InvalidEmailError` +- `InvalidPasswordError` +- `InvalidRankError` +- `InvalidAvatarError` +- `ValidationError` (catch all for odd validation errors) + + ## Field selecting For performance considerations, sometimes the client might want to choose the diff --git a/server/szurubooru/facade.py b/server/szurubooru/facade.py index cead9a2..1d26aad 100644 --- a/server/szurubooru/facade.py +++ b/server/szurubooru/facade.py @@ -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(): diff --git a/server/szurubooru/func/versions.py b/server/szurubooru/func/versions.py index d38130a..ee84407 100644 --- a/server/szurubooru/func/versions.py +++ b/server/szurubooru/func/versions.py @@ -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.') diff --git a/server/szurubooru/rest/app.py b/server/szurubooru/rest/app.py index da8f2dd..2c21916 100644 --- a/server/szurubooru/rest/app.py +++ b/server/szurubooru/rest/app.py @@ -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, } diff --git a/server/szurubooru/rest/errors.py b/server/szurubooru/rest/errors.py index 0189147..3c40b4c 100644 --- a/server/szurubooru/rest/errors.py +++ b/server/szurubooru/rest/errors.py @@ -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