Skip to content

Module stac_fastapi.api.errors

Error handling.

Variables

DEFAULT_STATUS_CODES
logger

Functions

add_exception_handlers

def add_exception_handlers(
    app: fastapi.applications.FastAPI,
    status_codes: Dict[Type[Exception], int]
) -> None

Add exception handlers to the FastAPI application.

Parameters:

Name Type Description Default
app None the FastAPI application. None
status_codes None mapping between exceptions and status codes. None

Returns:

Type Description
None None

exception_handler_factory

def exception_handler_factory(
    status_code: int
) -> Callable

Create a FastAPI exception handler for a particular status code.

Parameters:

Name Type Description Default
status_code None HTTP status code. None

Returns:

Type Description
callable an exception handler.

Classes

ErrorResponse

class ErrorResponse(
    /,
    *args,
    **kwargs
)

A JSON error response returned by the API.

The STAC API spec expects that code and description are both present in the payload.

Attributes

Name Type Description Default
code None A code representing the error, semantics are up to implementor. None
description None A description of the error. None

Ancestors (in MRO)

  • builtins.dict

Methods

clear

def clear(
    ...
)

D.clear() -> None. Remove all items from D.

copy

def copy(
    ...
)

D.copy() -> a shallow copy of D

fromkeys

def fromkeys(
    iterable,
    value=None,
    /
)

Create a new dictionary with keys from iterable and values set to value.

get

def get(
    self,
    key,
    default=None,
    /
)

Return the value for key if key is in the dictionary, else default.

items

def items(
    ...
)

D.items() -> a set-like object providing a view on D's items

keys

def keys(
    ...
)

D.keys() -> a set-like object providing a view on D's keys

pop

def pop(
    ...
)

D.pop(k[,d]) -> v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem

def popitem(
    self,
    /
)

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault

def setdefault(
    self,
    key,
    default=None,
    /
)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update

def update(
    ...
)

D.update([E, ]**F) -> None. Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values

def values(
    ...
)

D.values() -> an object providing a view on D's values