Module imandrax_api.twirp.errors

Classes

class Errors (*args, **kwds)
Expand source code
class Errors(StrEnum):
    Canceled = "canceled"
    Unknown = "unknown"
    InvalidArgument = "invalid_argument"
    DeadlineExceeded = "deadline_exceeded"
    NotFound = "not_found"
    BadRoute = "bad_route"
    AlreadyExists = "already_exists"
    PermissionDenied = "permission_denied"
    Unauthenticated = "unauthenticated"
    ResourceExhausted = "resource_exhausted"
    FailedPrecondition = "failed_precondition"
    Aborted = "aborted"
    OutOfRange = "out_of_range"
    Unimplemented = "unimplemented"
    Internal = "internal"
    Unavailable = "unavailable"
    DataLoss = "data_loss"
    Malformed = "malformed"
    NoError = ""

    @staticmethod
    def get_status_code(code):
        return {
            Errors.Canceled: 408,
            Errors.Unknown: 500,
            Errors.InvalidArgument: 400,
            Errors.Malformed: 400,
            Errors.DeadlineExceeded: 408,
            Errors.NotFound: 404,
            Errors.BadRoute: 404,
            Errors.AlreadyExists: 409,
            Errors.PermissionDenied: 403,
            Errors.Unauthenticated: 401,
            Errors.ResourceExhausted: 429,
            Errors.FailedPrecondition: 412,
            Errors.Aborted: 409,
            Errors.OutOfRange: 400,
            Errors.Unimplemented: 501,
            Errors.Internal: 500,
            Errors.Unavailable: 503,
            Errors.DataLoss: 500,
            Errors.NoError: 200,
        }.get(code, 500)

Enum where members are also (and must be) strings

Ancestors

  • enum.StrEnum
  • builtins.str
  • enum.ReprEnum
  • enum.Enum

Class variables

var Aborted
var AlreadyExists
var BadRoute
var Canceled
var DataLoss
var DeadlineExceeded
var FailedPrecondition
var Internal
var InvalidArgument
var Malformed
var NoError
var NotFound
var OutOfRange
var PermissionDenied
var ResourceExhausted
var Unauthenticated
var Unavailable
var Unimplemented
var Unknown

Static methods

def get_status_code(code)
Expand source code
@staticmethod
def get_status_code(code):
    return {
        Errors.Canceled: 408,
        Errors.Unknown: 500,
        Errors.InvalidArgument: 400,
        Errors.Malformed: 400,
        Errors.DeadlineExceeded: 408,
        Errors.NotFound: 404,
        Errors.BadRoute: 404,
        Errors.AlreadyExists: 409,
        Errors.PermissionDenied: 403,
        Errors.Unauthenticated: 401,
        Errors.ResourceExhausted: 429,
        Errors.FailedPrecondition: 412,
        Errors.Aborted: 409,
        Errors.OutOfRange: 400,
        Errors.Unimplemented: 501,
        Errors.Internal: 500,
        Errors.Unavailable: 503,
        Errors.DataLoss: 500,
        Errors.NoError: 200,
    }.get(code, 500)