pub trait ResponseCode {
    type ErrorCode: Serialize;
    type BusinessCode: Serialize;

    const OK: Self;
    const BAD_REQUEST: Self;
    const INTERNAL_SERVER_ERROR: Self;

    // Required methods
    fn status_code(&self) -> u16;
    fn is_success(&self) -> bool;

    // Provided methods
    fn error_code(&self) -> Option<Self::ErrorCode> { ... }
    fn business_code(&self) -> Option<Self::BusinessCode> { ... }
    fn type_uri(&self) -> Option<SharedString> { ... }
    fn title(&self) -> Option<SharedString> { ... }
    fn message(&self) -> Option<SharedString> { ... }
}
Expand description

Trait for response code. See Problem Details for HTTP APIs.

Required Associated Types§

source

type ErrorCode: Serialize

A type for the error code.

source

type BusinessCode: Serialize

A type for the business code.

Required Associated Constants§

source

const OK: Self

200 Ok.

source

const BAD_REQUEST: Self

400 Bad Request.

source

const INTERNAL_SERVER_ERROR: Self

500 Internal Server Error.

Required Methods§

source

fn status_code(&self) -> u16

Status code.

source

fn is_success(&self) -> bool

Returns true if the response is successful.

Provided Methods§

source

fn error_code(&self) -> Option<Self::ErrorCode>

Error code.

source

fn business_code(&self) -> Option<Self::BusinessCode>

Business code.

source

fn type_uri(&self) -> Option<SharedString>

A URI reference that identifies the problem type. For successful response, it should be None.

source

fn title(&self) -> Option<SharedString>

A short, human-readable summary of the problem type. For successful response, it should be None.

source

fn message(&self) -> Option<SharedString>

A context-specific descriptive message. If the response is not successful, it should be a human-readable explanation specific to this occurrence of the problem.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl ResponseCode for StatusCode

§

type ErrorCode = Cow<'static, str>

§

type BusinessCode = u16

source§

const OK: Self = StatusCode::OK

source§

const BAD_REQUEST: Self = StatusCode::BAD_REQUEST

source§

const INTERNAL_SERVER_ERROR: Self = StatusCode::INTERNAL_SERVER_ERROR