* Maps an HTTP status code to the appropriate error class
(status: number, message: string, data: unknown, response?: unknown)
| 159 | * Maps an HTTP status code to the appropriate error class |
| 160 | */ |
| 161 | protected mapByStatusCode(status: number, message: string, data: unknown, response?: unknown): BaseError { |
| 162 | switch (status) { |
| 163 | case 400: |
| 164 | return this.mapBadRequestError(message, data); |
| 165 | case 401: |
| 166 | return new AuthenticationError(message, this.exchangeName); |
| 167 | case 403: |
| 168 | return new PermissionDenied(message, this.exchangeName); |
| 169 | case 404: |
| 170 | return this.mapNotFoundError(message, data); |
| 171 | case 429: |
| 172 | return this.mapRateLimitError(message, response); |
| 173 | case 500: |
| 174 | case 502: |
| 175 | case 503: |
| 176 | case 504: |
| 177 | return new ExchangeNotAvailable( |
| 178 | `Exchange error (${status}): ${message}`, |
| 179 | this.exchangeName |
| 180 | ); |
| 181 | default: |
| 182 | return new BadRequest( |
| 183 | `HTTP ${status}: ${message}`, |
| 184 | this.exchangeName |
| 185 | ); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Maps 400 errors to specific bad request subtypes |
no test coverage detected