Exception: MeiliSearch::ApiError
- Defined in:
- lib/meilisearch/error.rb
Instance Attribute Summary collapse
-
#http_body ⇒ Object
readonly
:http_code # e.g.
-
#http_code ⇒ Object
readonly
:http_code # e.g.
-
#http_message ⇒ Object
readonly
:http_code # e.g.
-
#message ⇒ Object
readonly
:http_code # e.g.
-
#ms_code ⇒ Object
(also: #code)
readonly
:http_code # e.g.
-
#ms_link ⇒ Object
(also: #link)
readonly
:http_code # e.g.
-
#ms_message ⇒ Object
readonly
:http_code # e.g.
-
#ms_type ⇒ Object
(also: #type)
readonly
:http_code # e.g.
Instance Method Summary collapse
- #details ⇒ Object
-
#initialize(http_code, http_message, http_body) ⇒ ApiError
constructor
A new instance of ApiError.
- #parse_body(http_body) ⇒ Object
Constructor Details
#initialize(http_code, http_message, http_body) ⇒ ApiError
Returns a new instance of ApiError.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/meilisearch/error.rb', line 23 def initialize(http_code, , http_body) @http_code = http_code @http_message = @http_body = parse_body(http_body) @ms_code = @http_body['code'] @ms_type = @http_body['type'] @ms_message = @http_body.fetch('message', 'MeiliSearch API has not returned any error message') @ms_link = @http_body.fetch('link', '<no documentation link found>') @message = "#{http_code} #{} - #{@ms_message}. See #{ms_link}." super(details) end |
Instance Attribute Details
#http_body ⇒ Object (readonly)
:http_code # e.g. 400, 404… :http_message # e.g. Bad Request, Not Found… :http_body # The response body received from the MeiliSearch API :ms_code # The error code given by the MeiliSearch API :ms_type # The error type given by the MeiliSearch API :ms_link # The documentation link given by the MeiliSearch API :ms_message # The error message given by the MeiliSearch API :message # The detailed error message of this error class
17 18 19 |
# File 'lib/meilisearch/error.rb', line 17 def http_body @http_body end |
#http_code ⇒ Object (readonly)
:http_code # e.g. 400, 404… :http_message # e.g. Bad Request, Not Found… :http_body # The response body received from the MeiliSearch API :ms_code # The error code given by the MeiliSearch API :ms_type # The error type given by the MeiliSearch API :ms_link # The documentation link given by the MeiliSearch API :ms_message # The error message given by the MeiliSearch API :message # The detailed error message of this error class
17 18 19 |
# File 'lib/meilisearch/error.rb', line 17 def http_code @http_code end |
#http_message ⇒ Object (readonly)
:http_code # e.g. 400, 404… :http_message # e.g. Bad Request, Not Found… :http_body # The response body received from the MeiliSearch API :ms_code # The error code given by the MeiliSearch API :ms_type # The error type given by the MeiliSearch API :ms_link # The documentation link given by the MeiliSearch API :ms_message # The error message given by the MeiliSearch API :message # The detailed error message of this error class
17 18 19 |
# File 'lib/meilisearch/error.rb', line 17 def @http_message end |
#message ⇒ Object (readonly)
:http_code # e.g. 400, 404… :http_message # e.g. Bad Request, Not Found… :http_body # The response body received from the MeiliSearch API :ms_code # The error code given by the MeiliSearch API :ms_type # The error type given by the MeiliSearch API :ms_link # The documentation link given by the MeiliSearch API :ms_message # The error message given by the MeiliSearch API :message # The detailed error message of this error class
17 18 19 |
# File 'lib/meilisearch/error.rb', line 17 def @message end |
#ms_code ⇒ Object (readonly) Also known as: code
:http_code # e.g. 400, 404… :http_message # e.g. Bad Request, Not Found… :http_body # The response body received from the MeiliSearch API :ms_code # The error code given by the MeiliSearch API :ms_type # The error type given by the MeiliSearch API :ms_link # The documentation link given by the MeiliSearch API :ms_message # The error message given by the MeiliSearch API :message # The detailed error message of this error class
17 18 19 |
# File 'lib/meilisearch/error.rb', line 17 def ms_code @ms_code end |
#ms_link ⇒ Object (readonly) Also known as: link
:http_code # e.g. 400, 404… :http_message # e.g. Bad Request, Not Found… :http_body # The response body received from the MeiliSearch API :ms_code # The error code given by the MeiliSearch API :ms_type # The error type given by the MeiliSearch API :ms_link # The documentation link given by the MeiliSearch API :ms_message # The error message given by the MeiliSearch API :message # The detailed error message of this error class
17 18 19 |
# File 'lib/meilisearch/error.rb', line 17 def ms_link @ms_link end |
#ms_message ⇒ Object (readonly)
:http_code # e.g. 400, 404… :http_message # e.g. Bad Request, Not Found… :http_body # The response body received from the MeiliSearch API :ms_code # The error code given by the MeiliSearch API :ms_type # The error type given by the MeiliSearch API :ms_link # The documentation link given by the MeiliSearch API :ms_message # The error message given by the MeiliSearch API :message # The detailed error message of this error class
17 18 19 |
# File 'lib/meilisearch/error.rb', line 17 def @ms_message end |
#ms_type ⇒ Object (readonly) Also known as: type
:http_code # e.g. 400, 404… :http_message # e.g. Bad Request, Not Found… :http_body # The response body received from the MeiliSearch API :ms_code # The error code given by the MeiliSearch API :ms_type # The error type given by the MeiliSearch API :ms_link # The documentation link given by the MeiliSearch API :ms_message # The error message given by the MeiliSearch API :message # The detailed error message of this error class
17 18 19 |
# File 'lib/meilisearch/error.rb', line 17 def ms_type @ms_type end |
Instance Method Details
#details ⇒ Object
50 51 52 |
# File 'lib/meilisearch/error.rb', line 50 def details "MeiliSearch::ApiError - code: #{@ms_code} - type: #{ms_type} - message: #{@ms_message} - link: #{ms_link}" end |
#parse_body(http_body) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/meilisearch/error.rb', line 35 def parse_body(http_body) if http_body.respond_to?(:to_hash) http_body.to_hash elsif http_body.respond_to?(:to_str) JSON.parse(http_body.to_str) else {} end rescue JSON::ParserError # We might receive a JSON::ParserError when, for example, MeiliSearch is running behind # some proxy (ELB or Nginx, for example), and the request timeouts, returning us # a raw HTML body instead of a JSON as we were expecting { 'message' => "The server has not returned a valid JSON HTTP body: #{http_body}" } end |