Exception: BetterAuth::APIError
- Defined in:
- lib/better_auth/api_error.rb
Constant Summary collapse
- STATUS_CODES =
{ "BAD_REQUEST" => 400, "UNAUTHORIZED" => 401, "UNAUTHORIZED_INVALID_OR_EXPIRED_NONCE" => 401, "FORBIDDEN" => 403, "CONFLICT" => 409, "NOT_FOUND" => 404, "METHOD_NOT_ALLOWED" => 405, "UNPROCESSABLE_ENTITY" => 422, "TOO_MANY_REQUESTS" => 429, "BAD_GATEWAY" => 502, "NOT_IMPLEMENTED" => 501, "FOUND" => 302, "INTERNAL_SERVER_ERROR" => 500 }.freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Instance Method Summary collapse
-
#initialize(status, message: nil, headers: {}, code: nil, body: nil) ⇒ APIError
constructor
A new instance of APIError.
- #to_h ⇒ Object
Constructor Details
#initialize(status, message: nil, headers: {}, code: nil, body: nil) ⇒ APIError
Returns a new instance of APIError.
23 24 25 26 27 28 29 30 |
# File 'lib/better_auth/api_error.rb', line 23 def initialize(status, message: nil, headers: {}, code: nil, body: nil) @status = status.to_s.upcase @status_code = STATUS_CODES.fetch(@status, 500) @headers = normalize_headers(headers) @code = code || @status @body = body super( || ) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
21 22 23 |
# File 'lib/better_auth/api_error.rb', line 21 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
21 22 23 |
# File 'lib/better_auth/api_error.rb', line 21 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
21 22 23 |
# File 'lib/better_auth/api_error.rb', line 21 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
21 22 23 |
# File 'lib/better_auth/api_error.rb', line 21 def status @status end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
21 22 23 |
# File 'lib/better_auth/api_error.rb', line 21 def status_code @status_code end |
Instance Method Details
#to_h ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/better_auth/api_error.rb', line 32 def to_h return body if body { code: code, message: } end |