Error Types

Complete reference for Azu's built-in error types.

Base Error Class

Azu::Response::Error

Base class for all HTTP errors.

class Azu::Response::Error < Exception
  getter status : Int32
  getter message : String
  getter context : ErrorContext?

  def initialize(@message : String, @status : Int32 = 500, @context : ErrorContext? = nil)
  end
end

Properties:

  • status : Int32 - HTTP status code

  • message : String - Error message

  • context : ErrorContext? - Additional context

Client Errors (4xx)

BadRequest (400)

Invalid request from client.

Usage: Malformed requests, invalid data formats

Unauthorized (401)

Authentication required.

Usage: Missing or invalid authentication

Forbidden (403)

Access denied despite authentication.

Usage: Authenticated but not authorized

NotFound (404)

Resource not found.

Usage: Resource doesn't exist

MethodNotAllowed (405)

HTTP method not supported.

Usage: Wrong HTTP method for endpoint

Conflict (409)

Request conflicts with current state.

Usage: Duplicate records, version conflicts

Gone (410)

Resource permanently deleted.

Usage: Deprecated resources

UnprocessableEntity (422)

Validation failed.

Usage: Invalid but well-formed requests

ValidationError (422)

Validation error with details.

Properties:

  • errors : Array(NamedTuple(field: String, message: String))

JSON Response:

TooManyRequests (429)

Rate limit exceeded.

Usage: Rate limiting

Server Errors (5xx)

InternalServerError (500)

Unexpected server error.

Usage: Unhandled exceptions

NotImplemented (501)

Feature not implemented.

Usage: Placeholder for future features

BadGateway (502)

Invalid response from upstream.

Usage: Proxy/gateway errors

ServiceUnavailable (503)

Service temporarily unavailable.

Usage: Maintenance, overload

GatewayTimeout (504)

Upstream timeout.

Usage: External service timeouts

ErrorContext

Additional context for debugging.

Creating Custom Errors

Error Response Format

Default JSON format:

With details:

Development mode:

HTTP Status Codes Summary

Code
Name
Class

400

Bad Request

BadRequest

401

Unauthorized

Unauthorized

403

Forbidden

Forbidden

404

Not Found

NotFound

405

Method Not Allowed

MethodNotAllowed

409

Conflict

Conflict

410

Gone

Gone

422

Unprocessable Entity

UnprocessableEntity

429

Too Many Requests

TooManyRequests

500

Internal Server Error

InternalServerError

501

Not Implemented

NotImplemented

502

Bad Gateway

BadGateway

503

Service Unavailable

ServiceUnavailable

504

Gateway Timeout

GatewayTimeout

See Also

Last updated

Was this helpful?