| 14 | * It should be used only for diagnostic purposes. |
| 15 | */ |
| 16 | export class DiagnosticHTTPClient extends EventsGenerator implements ProtonDriveHTTPClient { |
| 17 | constructor(private httpClient: ProtonDriveHTTPClient) { |
| 18 | super(); |
| 19 | this.httpClient = httpClient; |
| 20 | } |
| 21 | |
| 22 | async fetchJson(options: ProtonDriveHTTPClientJsonRequest): Promise<Response> { |
| 23 | try { |
| 24 | const response = await this.httpClient.fetchJson(options); |
| 25 | |
| 26 | if (response.status >= 400 && response.status !== 429) { |
| 27 | try { |
| 28 | const json = await response.json(); |
| 29 | |
| 30 | this.enqueueEvent({ |
| 31 | type: 'http_error', |
| 32 | request: { |
| 33 | url: options.url, |
| 34 | method: options.method, |
| 35 | json: options.json, |
| 36 | }, |
| 37 | response: { |
| 38 | status: response.status, |
| 39 | statusText: response.statusText, |
| 40 | json, |
| 41 | }, |
| 42 | }); |
| 43 | |
| 44 | return new Response(JSON.stringify(json), { |
| 45 | status: response.status, |
| 46 | statusText: response.statusText, |
| 47 | headers: response.headers, |
| 48 | }); |
| 49 | } catch (jsonError: unknown) { |
| 50 | this.enqueueEvent({ |
| 51 | type: 'http_error', |
| 52 | request: { |
| 53 | url: options.url, |
| 54 | method: options.method, |
| 55 | json: options.json, |
| 56 | }, |
| 57 | response: { |
| 58 | status: response.status, |
| 59 | statusText: response.statusText, |
| 60 | jsonError, |
| 61 | }, |
| 62 | }); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return response; |
| 67 | } catch (error: unknown) { |
| 68 | this.enqueueEvent({ |
| 69 | type: 'http_error', |
| 70 | request: { |
| 71 | url: options.url, |
| 72 | method: options.method, |
| 73 | json: options.json, |
nothing calls this directly
no outgoing calls
no test coverage detected