Exception: Notion::APIError
- Defined in:
- lib/notion/errors.rb
Direct Known Subclasses
BadRequestError, ConflictError, ObjectNotFoundError, RateLimitedError, RestrictedResourceError, ServerError, UnauthorizedError
Constant Summary collapse
- ERROR_CODES =
{ "invalid_json" => InvalidJSONError, "invalid_request_url" => InvalidRequestURLError, "invalid_request" => InvalidRequestError, "invalid_grant" => InvalidGrantError, "validation_error" => ValidationError, "missing_version" => MissingVersionError, "invalid_beta" => InvalidBetaError, "unauthorized" => UnauthorizedError, "restricted_resource" => RestrictedResourceError, "object_not_found" => ObjectNotFoundError, "conflict_error" => ConflictError, "rate_limited" => RateLimitedError, "internal_server_error" => InternalServerError, "bad_gateway" => BadGatewayError, "service_unavailable" => ServiceUnavailableError, "database_connection_unavailable" => DatabaseConnectionUnavailableError, "gateway_timeout" => GatewayTimeoutError, "service_overload" => ServiceOverloadError }.freeze
- STATUS_ERRORS =
{ 400 => BadRequestError, 401 => UnauthorizedError, 403 => RestrictedResourceError, 404 => ObjectNotFoundError, 409 => ConflictError, 429 => RateLimitedError, 500 => InternalServerError, 502 => BadGatewayError, 503 => ServiceUnavailableError, 504 => GatewayTimeoutError, 529 => ServiceOverloadError }.freeze
Instance Attribute Summary collapse
-
#additional_data ⇒ Object
readonly
Returns the value of attribute additional_data.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#retry_after ⇒ Object
readonly
Returns the value of attribute retry_after.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(response) ⇒ APIError
constructor
A new instance of APIError.
- #retryable? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ APIError
Returns a new instance of APIError.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/notion/errors.rb', line 20 def initialize(response) unless response.respond_to?(:body) super(response.to_s) return end body = response.body.is_a?(Hash) ? response.body : {} @status = response.status @code = body["code"] @request_id = response.request_id || body["request_id"] @additional_data = body["additional_data"] @retry_after = response.headers["retry-after"]&.to_f @response = response super(body["message"] || "Notion API request failed with status #{@status}") end |
Instance Attribute Details
#additional_data ⇒ Object (readonly)
Returns the value of attribute additional_data.
18 19 20 |
# File 'lib/notion/errors.rb', line 18 def additional_data @additional_data end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
18 19 20 |
# File 'lib/notion/errors.rb', line 18 def code @code end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
18 19 20 |
# File 'lib/notion/errors.rb', line 18 def request_id @request_id end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
18 19 20 |
# File 'lib/notion/errors.rb', line 18 def response @response end |
#retry_after ⇒ Object (readonly)
Returns the value of attribute retry_after.
18 19 20 |
# File 'lib/notion/errors.rb', line 18 def retry_after @retry_after end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
18 19 20 |
# File 'lib/notion/errors.rb', line 18 def status @status end |
Class Method Details
.from_response(response) ⇒ Object
40 41 42 43 |
# File 'lib/notion/errors.rb', line 40 def self.from_response(response) code = response.body.is_a?(Hash) && response.body["code"] (ERROR_CODES[code] || STATUS_ERRORS[response.status] || self).new(response) end |
Instance Method Details
#retryable? ⇒ Boolean
36 37 38 |
# File 'lib/notion/errors.rb', line 36 def retryable? status == 429 || status == 529 || status.between?(500, 599) end |