Exception: MeiliSearch::ApiError
- Inherits:
-
StandardError
- Object
- StandardError
- 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
- #get_meilisearch_error_info(http_body) ⇒ Object
-
#initialize(http_code, http_message, http_body) ⇒ ApiError
constructor
A new instance of ApiError.
Constructor Details
#initialize(http_code, http_message, http_body) ⇒ ApiError
Returns a new instance of ApiError.
20 21 22 23 24 25 26 27 28 |
# File 'lib/meilisearch/error.rb', line 20 def initialize(http_code, , http_body) get_meilisearch_error_info(http_body) unless http_body.nil? || http_body.empty? @http_code = http_code @http_message = @ms_message ||= 'MeiliSearch API has not returned any error message' @ms_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
14 15 16 |
# File 'lib/meilisearch/error.rb', line 14 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
14 15 16 |
# File 'lib/meilisearch/error.rb', line 14 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
14 15 16 |
# File 'lib/meilisearch/error.rb', line 14 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
14 15 16 |
# File 'lib/meilisearch/error.rb', line 14 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
14 15 16 |
# File 'lib/meilisearch/error.rb', line 14 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
14 15 16 |
# File 'lib/meilisearch/error.rb', line 14 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
14 15 16 |
# File 'lib/meilisearch/error.rb', line 14 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
14 15 16 |
# File 'lib/meilisearch/error.rb', line 14 def ms_type @ms_type end |
Instance Method Details
#details ⇒ Object
43 44 45 |
# File 'lib/meilisearch/error.rb', line 43 def details "MeiliSearch::ApiError - code: #{@ms_code} - type: #{ms_type} - message: #{@ms_message} - link: #{ms_link}" end |
#get_meilisearch_error_info(http_body) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/meilisearch/error.rb', line 30 def get_meilisearch_error_info(http_body) @http_body = JSON.parse(http_body) @ms_code = @http_body['code'] @ms_message = @http_body['message'] @ms_type = @http_body['type'] @ms_link = @http_body['link'] 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 @ms_message = "The server has not returned a valid JSON HTTP body: #{http_body}" end |