Return application/problem+json format errors and provide error endpoint
to dereference error codes.
This commit is contained in:
parent
8c81915f38
commit
9c08717173
7 changed files with 156 additions and 39 deletions
56
endpoints/api/error.py
Normal file
56
endpoints/api/error.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
""" Error details API """
|
||||
from flask import url_for
|
||||
from enum import Enum
|
||||
|
||||
from endpoints.api import (resource, nickname, ApiResource, NotFound, path_param,
|
||||
define_json_response, ApiErrorType, ERROR_DESCRIPTION)
|
||||
|
||||
|
||||
def error_view(error_type):
|
||||
return {
|
||||
'type': url_for('error', error_type=error_type, _external=True),
|
||||
'title': error_type,
|
||||
'description': ERROR_DESCRIPTION[error_type]
|
||||
}
|
||||
|
||||
|
||||
@resource('/v1/error/<error_type>')
|
||||
@path_param('error_type', 'The error code identifying the type of error.')
|
||||
class Error(ApiResource):
|
||||
""" Resource for manging an organization's teams. """
|
||||
schemas = {
|
||||
'ApiError': {
|
||||
'type': 'object',
|
||||
'description': 'Description of an error',
|
||||
'required': [
|
||||
'type',
|
||||
'properties',
|
||||
'title',
|
||||
],
|
||||
'properties': {
|
||||
'type': {
|
||||
'type': 'string',
|
||||
'description': 'A reference to the error type resource'
|
||||
},
|
||||
'title': {
|
||||
'type': 'string',
|
||||
'description': 'The title of the error. Can be used to uniquely identify the kind of error.',
|
||||
'enum': list(ApiErrorType.__members__)
|
||||
},
|
||||
'description': {
|
||||
'type': 'string',
|
||||
'description': 'A more detailed description of the error that may include help for fixing the issue.'
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@define_json_response('ApiError')
|
||||
@nickname('getError')
|
||||
def get(self, error_type):
|
||||
""" Get a detailed description of the error """
|
||||
if error_type in ERROR_DESCRIPTION.keys():
|
||||
return error_view(error_type), 200
|
||||
else:
|
||||
raise NotFound()
|
||||
|
Reference in a new issue