(
options: Types.Options,
httpOk: number = 0
)
| 2 | import * as Types from "./types.js"; |
| 3 | |
| 4 | export const QueryHelper = async ( |
| 5 | options: Types.Options, |
| 6 | httpOk: number = 0 |
| 7 | ): Promise<Types.APIResponse> => { |
| 8 | let output: Types.APIResponse = {}; |
| 9 | try { |
| 10 | const result = await axios.request(options); |
| 11 | if (httpOk <= 0) { |
| 12 | output = { |
| 13 | error: new Error(`No default http ok condition specified`), |
| 14 | }; |
| 15 | } else { |
| 16 | switch (httpOk) { |
| 17 | case 200: |
| 18 | output = { |
| 19 | data: result.data, |
| 20 | }; |
| 21 | break; |
| 22 | case 204: |
| 23 | output = { |
| 24 | data: null, |
| 25 | }; |
| 26 | break; |
| 27 | default: |
| 28 | output = { |
| 29 | error: new Error(`Bad http ok condition`), |
| 30 | }; |
| 31 | } |
| 32 | } |
| 33 | } catch (err: any) { |
| 34 | output = { |
| 35 | error: new Error( |
| 36 | `${err.response.status}: ${err.response.data.title}. Detail: ${err.response.data.detail}` |
| 37 | ), |
| 38 | }; |
| 39 | } |
| 40 | |
| 41 | return output; |
| 42 | }; |
no outgoing calls
no test coverage detected