| 25 | | undefined, |
| 26 | > extends Error { |
| 27 | /** HTTP status for the response that caused the error */ |
| 28 | readonly status: TStatus; |
| 29 | /** HTTP headers for the response that caused the error */ |
| 30 | readonly headers: THeaders; |
| 31 | /** JSON body of the response that caused the error */ |
| 32 | readonly error: TError; |
| 33 | |
| 34 | constructor( |
| 35 | status: TStatus, |
| 36 | error: TError, |
| 37 | message: string | undefined, |
| 38 | headers: THeaders, |
| 39 | ) { |
| 40 | super(APIError.makeMessage(status, error, message)); |
| 41 | this.status = status; |
| 42 | this.headers = headers; |
| 43 | this.error = error; |
| 44 | } |
| 45 | |
| 46 | hasReason(reason: string) { |
| 47 | const errors = this.error?.error.errors; |
| 48 | |
| 49 | if (!errors) { |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | return errors.some((error) => error.reason === reason); |