messua/err

An error type made to be converted into an error response.

Types

The Error variant of the MResponse type.

It will be converted to an actual gleam/http.Response once it’s out of your handler’s hands. You can optionally give it “log message” (distinct from the body message and not returned with the response—intended only for a little visibility of server errors) that will be logged by the log Layer from the messua/mware module. (Alternatively, of course, you can write your own logging Layer that uses these.)

pub type Err {
  Err(
    status: Int,
    headers: List(http.Header),
    log_msg: Option(StringBuilder),
    body_msg: Option(StringBuilder),
  )
}

Constructors

  • Err(
      status: Int,
      headers: List(http.Header),
      log_msg: Option(StringBuilder),
      body_msg: Option(StringBuilder),
    )

    Arguments

    • status

      Response status code. This will probably be in the 4xx or 5xx range. Many of the messua/aux.require_xxx functions return 400 errors on failure.

    • headers

      Any additional headers you want to provide; these are not generally required.

    • log_msg

      An optional diagnostic message for the server administrator’s benefit.

    • body_msg

      An optional message to send as the body of the response.

Functions

pub fn log(e: Err, msg: List(String)) -> Err

Add a log message to the given response.

The message is supplied as a list of strings that will get joined with no intervening content.

pub fn new(status: Int) -> Err

Instantiate a new message with the given status code.

pub fn to_response(
  e: Err,
  logger: fn(StringBuilder) -> Nil,
) -> Response(ResponseData)

This function is used by the handler harness to convert the Err to a proper Response before shooting it back down the pipe.

pub fn with_message(e: Err, msg: List(String)) -> Err

Add a body message to the given response.

The message is supplied as a list of strings that will get joined with no intervening content, but will have a \n suffixed.

Search Document