class
Radbas::HTTPError
- Radbas::HTTPError
- Exception
- Reference
- Object
Overview
Raised to end a request with an HTTP error status.
CommonErrorHandler answers it with Problem Details (RFC 9457): message becomes #detail,
type and title the members of the same name. With no type (about:blank), #title is
always the status description. headers are sent with the error response,
e.g. WWW-Authenticate for 401 or Allow for 405.
raise Radbas::HTTPError.new(:not_found)
raise Radbas::HTTPError.new(:bad_request, "missing name")
raise Radbas::HTTPError.new(:forbidden, "balance too low", type: "https://example.com/probs/out-of-credit", title: "Out of credit")
Subclasses add members to the body by overriding #write_extensions.
Defined in:
radbas-framework/http_error.crConstant Summary
-
ABOUT_BLANK =
"about:blank"
Constructors
Instance Method Summary
-
#detail : String | Nil
The message as given,
nilif none was given. - #headers : HTTP::Headers
- #status : HTTP::Status
-
#title : String
A short summary of the problem type.
-
#type : String
The problem type, a URI reference.
-
#write_extensions(json : JSON::Builder) : Nil
Writes extension members into the Problem Details object, nothing by default.
Constructor Detail
def self.new(status : HTTP::Status, message : String | Nil = nil, headers : HTTP::Headers = HTTP::Headers.new, cause : Exception | Nil = nil, type : String | Nil = nil, title : String | Nil = nil)
#
Instance Method Detail
def write_extensions(json : JSON::Builder) : Nil
#
Writes extension members into the Problem Details object, nothing by default.
class ValidationProblem < Radbas::HTTPError
def initialize(@errors : Array(FieldError))
super(:unprocessable_entity, "invalid input")
end
def write_extensions(json : JSON::Builder) : Nil
json.field("errors") { @errors.to_json(json) }
end
end