starlette_jsonapi.exceptions module

exception starlette_jsonapi.exceptions.JSONAPIException(status_code, detail=None, errors=None)

Bases: HTTPException

HTTP exception with json:api representation.

Parameters
  • status_code (int) –

  • detail (str) –

  • errors (List[dict]) –

Return type

None

__init__(status_code, detail=None, errors=None)

Base json:api exception class.

Parameters
  • status_code (int) – HTTP status code

  • detail (Optional[str]) – Optional, error detail, will be serialized in the final HTTP response. DO NOT include sensitive information here. If not specified, the HTTP message associated to status_code will be used.

  • errors (Optional[List[dict]]) –

    Optional, list of json:api error representations. Used if multiple errors are returned.

    import json
    from starlette_jsonapi.utils import serialize_error
    
    error1 = JSONAPIException(400, 'foo')
    error2 = JSONAPIException(400, 'bar')
    final_error = JSONAPIException(
        400, 'final', errors=error1.errors + error2.errors
    )
    response = serialize_error(final_error)
    assert json.loads(response.body)['errors'] == [
        {'detail': 'foo'},
        {'detail': 'bar'},
        {'detail': 'final'},
    ]
    

Return type

None

exception starlette_jsonapi.exceptions.ResourceNotFound(status_code=None, detail=None)

Bases: JSONAPIException

HTTP 404 error, serialized according to json:api.

Parameters
  • status_code (int) –

  • detail (str) –

Return type

None

status_code: int = 404
detail: str = 'Resource object not found.'
__init__(status_code=None, detail=None)
Parameters
  • status_code (Optional[int]) –

  • detail (Optional[str]) –

Return type

None