Class: Notion::Http::Middlewares::RaiseError
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Notion::Http::Middlewares::RaiseError
- Defined in:
- lib/notion/http/middlewares/raise_error.rb
Overview
A middleware that raise Notion::Errors::HttpError
Instance Method Summary collapse
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/notion/http/middlewares/raise_error.rb', line 22 def call(env) super rescue ::Faraday::TimeoutError, ::Faraday::ConnectionFailed raise Notion::Errors::TimeoutError.new("timeout_error", "A unified client error for timeouts") rescue ::Faraday::ParsingError = "Raised by middlewares that parse the response, like the JSON response middleware." raise Notion::Errors::ParsingError.new("parsing_error", , env.response) end |
#on_complete(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/notion/http/middlewares/raise_error.rb', line 8 def on_complete(env) return if env.success? body = env.body return unless body error_code = body["code"] = body["message"] error_class = Notion::Errors::NOTION_ERROR_CODES[error_code] error_class ||= Notion::Errors::HttpError raise error_class.new(error_code, , env.response) end |