aboutsummaryrefslogtreecommitdiffstats
path: root/src/services
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-11-15 12:24:42 +0100
committerArmand Philippot <git@armandphilippot.com>2023-11-15 17:26:16 +0100
commit0f38aee374029213a47ef7c29bd164093fe63c85 (patch)
tree290cb6471fdfe81e4c42f4da4729247536b04ee7 /src/services
parentbe4d907efb4e2fa658baa7c9b276ed282eb920db (diff)
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.
Diffstat (limited to 'src/services')
-rw-r--r--src/services/graphql/api.ts19
1 files changed, 9 insertions, 10 deletions
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 <T, K extends Queries | Mutations>({
type JSONResponse = {
data?: FetchAPIResponse<T, K>;
- errors?: Array<{ message: string }>;
+ errors?: { message: string }[];
};
const { data, errors }: JSONResponse = await response.json();
@@ -74,11 +74,10 @@ export const fetchAPI = async <T, K extends Queries | Mutations>({
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);
};