|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require_relative 'mindee_error' |
| 4 | +require_relative '../parsing/v2/error_item' |
4 | 5 |
|
5 | 6 | module Mindee |
6 | 7 | module Errors |
7 | 8 | # API V2 HttpError |
8 | 9 | class MindeeHTTPErrorV2 < MindeeError |
9 | | - # @return [Integer] |
| 10 | + # @return [Integer] The HTTP status code returned by the server. |
10 | 11 | attr_reader :status |
11 | | - # @return [String] |
| 12 | + # @return [String] A human-readable explanation specific to the occurrence of the problem. |
12 | 13 | attr_reader :detail |
| 14 | + # @return [String] A short, human-readable summary of the problem. |
| 15 | + attr_reader :title |
| 16 | + # @return [String] A machine-readable code specific to the occurrence of the problem. |
| 17 | + attr_reader :code |
| 18 | + # @return [Array<ErrorItem>] A list of explicit error details. |
| 19 | + attr_reader :errors |
13 | 20 |
|
14 | 21 | # @param http_error [Hash, Parsing::V2::ErrorResponse] |
15 | 22 | def initialize(http_error) |
16 | 23 | if http_error.is_a?(Parsing::V2::ErrorResponse) |
17 | 24 | http_error = { 'detail' => http_error.detail, |
18 | | - 'status' => http_error.status } |
| 25 | + 'status' => http_error.status, |
| 26 | + 'title' => http_error.title, |
| 27 | + 'code' => http_error.code, |
| 28 | + 'errors' => http_error.errors } |
19 | 29 | end |
20 | 30 | @status = http_error['status'] |
21 | 31 | @detail = http_error['detail'] |
22 | | - super("HTTP error: #{@status} - #{@detail}") |
| 32 | + @title = http_error['title'] |
| 33 | + @code = http_error['code'] |
| 34 | + @errors = if http_error.key?('errors') |
| 35 | + http_error['errors'].map do |error| |
| 36 | + Parsing::V2::ErrorItem.new(error) |
| 37 | + end |
| 38 | + else |
| 39 | + [] |
| 40 | + end |
| 41 | + super("HTTP #{@status} - #{@title} :: #{@code} - #{@detail}") |
23 | 42 | end |
24 | 43 | end |
25 | 44 | end |
|
0 commit comments