Module: Deepgram::ResponseHandler
- Included in:
- Base
- Defined in:
- lib/deepgram/response_handler.rb
Overview
The ResponseHandler module provides a method for handling responses from the Deepgram API and raising appropriate exceptions based on the HTTP status code.
Instance Method Summary collapse
-
#handle_response(res) ⇒ Faraday::Response
Handles the response from the Deepgram API.
Instance Method Details
#handle_response(res) ⇒ Faraday::Response
Handles the response from the Deepgram API.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/deepgram/response_handler.rb', line 24 def handle_response(res) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity case res.status when 200..226 then res when 400 then raise Deepgram::BadRequest.new(res.body, code: res.status, headers: res.headers) when 401 then raise Deepgram::Unauthorized.new(res.body, code: res.status, headers: res.headers) when 403 then raise Deepgram::Forbidden.new(res.body, code: res.status, headers: res.headers) when 404 then raise Deepgram::NotFound.new(res.body, code: res.status, headers: res.headers) when 429 then raise Deepgram::RateLimitExceeded.new(res.body, code: res.status, headers: res.headers) when 500 then raise Deepgram::InternalServerError.new(res.body, code: res.status, headers: res.headers) when 502 then raise Deepgram::BadGateway.new(res.body, code: res.status, headers: res.headers) when 503 then raise Deepgram::ServiceUnavailable.new(res.body, code: res.status, headers: res.headers) end end |