Class: Asimov::ApiV1::ApiErrorTranslator
- Inherits:
-
Object
- Object
- Asimov::ApiV1::ApiErrorTranslator
- Defined in:
- lib/asimov/api_v1/api_error_translator.rb
Overview
Translates errors which are generated by OpenAI and provided in responses to raised exceptions. Because OpenAI doesn’t currently provide any error-specific codes above and beyond the HTTP return code, this matching process is done by matching against message text which makes it somewhat fragile.
Class Method Summary collapse
-
.translate(resp) ⇒ Object
This method raises an appropriate Asimov::RequestError subclass if the response corresponds to an HTTP error.
Class Method Details
.translate(resp) ⇒ Object
This method raises an appropriate Asimov::RequestError subclass if the response corresponds to an HTTP error.
encapsulating the server response.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/asimov/api_v1/api_error_translator.rb', line 18 def self.translate(resp) return if resp.code == 200 match_400(resp) match_401(resp) match_404(resp) match_409(resp) match_429(resp) raise Asimov::RequestError, (resp) end |