From 0f38aee374029213a47ef7c29bd164093fe63c85 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Wed, 15 Nov 2023 12:24:42 +0100 Subject: refactor(hooks): remove useSettings hook It does not make sense to re-export an existing object through a hook. On some pages both the hook and the object was imported... It is better to use the CONFIG (previously settings) object directly and by doing it we avoid potential errors because of conditional hooks. --- src/services/graphql/api.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/services/graphql/api.ts') diff --git a/src/services/graphql/api.ts b/src/services/graphql/api.ts index 5f32a78..003f92d 100644 --- a/src/services/graphql/api.ts +++ b/src/services/graphql/api.ts @@ -1,4 +1,4 @@ -import { +import type { Mutations, MutationsInputMap, MutationsResponseMap, @@ -6,7 +6,7 @@ import { QueriesInputMap, QueriesResponseMap, } from '../../types'; -import { settings } from '../../utils/config'; +import { CONFIG } from '../../utils/config'; /** * Retrieve the API url from settings. @@ -14,7 +14,7 @@ import { settings } from '../../utils/config'; * @returns {string} The API url. */ export const getAPIUrl = (): string => { - const { url } = settings.api; + const { url } = CONFIG.api; if (!url) { throw new Error('API url is not defined.'); @@ -65,7 +65,7 @@ export const fetchAPI = async ({ type JSONResponse = { data?: FetchAPIResponse; - errors?: Array<{ message: string }>; + errors?: { message: string }[]; }; const { data, errors }: JSONResponse = await response.json(); @@ -74,11 +74,10 @@ export const fetchAPI = async ({ if (!data) return Promise.reject(new Error(`No data found"`)); return data; - } else { - console.error('Failed to fetch API'); - const error = new Error( - errors?.map((e) => e.message).join('\n') ?? 'unknown' - ); - return Promise.reject(error); } + console.error('Failed to fetch API'); + const error = new Error( + errors?.map((e) => e.message).join('\n') ?? 'unknown' + ); + return Promise.reject(error); }; -- cgit v1.2.3