پرش به محتویات

خطاها

این صفحه از docstringهای خود کد ساخته می‌شود، که به انگلیسی‌اند.

exceptions

A project's own errors, and the common ones the library ships.

A DomainError is DRF's APIException with one thing added: data, what a client can act on - which record is in the way, how long to wait:

class ProvinceInUse(DomainError):
    status_code = 409
    default_code = 'province_in_use'
    default_detail = _('This province has branches and cannot be deleted.')

raise ProvinceInUse(data={'branches': 3})

Its names are DRF's own: default_code is sent as error_code, default_detail as message. Being an APIException, it answers sensibly under DRF's own handler too, and a Celery task or a management command catches it like any other exception.

Where DRF has an exception of the same meaning, the library's is also that exception - NotFoundError is a NotFound - so code that catches DRF's, and DRF's own handling of it, keep working.

DomainError

DomainError(detail: Any = None, code: str | None = None, *, data: Mapping[str, Any] | None = None)

Bases: APIException

A rule of the project was broken, said in the envelope with data beside it.

InvalidInputError

InvalidInputError(detail: Any = None, code: str | None = None, *, data: Mapping[str, Any] | None = None)

Bases: DomainError

What was sent cannot be used - said by a service, where no serializer is.

InvalidCursorError

InvalidCursorError(detail: Any = None, code: str | None = None, *, data: Mapping[str, Any] | None = None)

Bases: DomainError

A cursor the server cannot read: the client sent back something it was never given.

AuthenticationFailedError

AuthenticationFailedError(detail: Any = None, code: str | None = None, *, data: Mapping[str, Any] | None = None)

Bases: DomainError, AuthenticationFailed

The credentials sent are wrong, or no longer good.

PermissionDeniedError

PermissionDeniedError(detail: Any = None, code: str | None = None, *, data: Mapping[str, Any] | None = None)

Bases: DomainError, PermissionDenied

The caller is known, and may not do this.

NotFoundError

NotFoundError(detail: Any = None, code: str | None = None, *, data: Mapping[str, Any] | None = None)

Bases: DomainError, NotFound

The record does not exist - or does not exist for this caller.

ConflictError

ConflictError(detail: Any = None, code: str | None = None, *, data: Mapping[str, Any] | None = None)

Bases: DomainError

The request is right, and the state of things refuses it.

RateLimitedError

RateLimitedError(detail: Any = None, code: str | None = None, *, data: Mapping[str, Any] | None = None)

Bases: DomainError

Too many attempts, too quickly. Put retry_after in data when it is known.

ServiceUnavailableError

ServiceUnavailableError(detail: Any = None, code: str | None = None, *, data: Mapping[str, Any] | None = None)

Bases: DomainError

Something the server depends on is not answering.