exceptions

Common exceptions and handlers for DM Product Service.

Classes

InvalidTokenAudience

Raised when the Bearer token has the wrong audience for this service.

MissingToken

Raised when no Bearer token is present in the request.

PathOutsideStorageArea

Raised when the requested path is outside the allowed storage base path.

PermissionDenied

Raised when the caller is not authorised for a route.

Functions

handle_exceptions(func)

Decorator to convert internal exceptions to HTTP responses.

Module Contents

class exceptions.InvalidTokenAudience(aapi_url='', service='')

Bases: fastapi.HTTPException

Raised when the Bearer token has the wrong audience for this service.

Returns an IVOA AuthVO 401 challenge with an exchange_url pointing to the AAPI token exchange endpoint so the client knows exactly how to obtain a service-scoped token.

Parameters:
  • aapi_url (str) –

  • service (str) –

class exceptions.MissingToken

Bases: fastapi.HTTPException

Raised when no Bearer token is present in the request.

Returns an IVOA AuthVO 401 challenge. Extends HTTPException so that FastAPI handles it correctly whether raised from a route handler or a Depends() dependency.

class exceptions.PathOutsideStorageArea(path)

Bases: fastapi.HTTPException

Raised when the requested path is outside the allowed storage base path.

Parameters:

path (str) –

message = 'Path outside allowed storage area: Uninferable'
class exceptions.PermissionDenied(message='You do not have permission to access this resource.')

Bases: fastapi.HTTPException

Raised when the caller is not authorised for a route.

Extends HTTPException directly so it is handled correctly by FastAPI whether raised inside a route handler or inside a Depends() dependency.

Parameters:

message (str) –

message = 'You do not have permission to access this resource.'
exceptions.handle_exceptions(func)

Decorator to convert internal exceptions to HTTP responses.