chore: make packages build

This commit is contained in:
Bassel Kanso 2024-04-24 09:25:54 +03:00
parent 620bcfe40d
commit 4d66c3c521
4 changed files with 32 additions and 31 deletions

View File

@ -19,12 +19,13 @@ describe('useAPIErrorHandler', () => {
const message = result.current.formatAPIError( const message = result.current.formatAPIError(
new FetchError('Error occured', { new FetchError('Error occured', {
data: null, data: {
error: { error: {
name: 'ApplicationError', name: 'ApplicationError',
message: 'Field contains errors', message: 'Field contains errors',
details: {}, details: {},
}, },
},
}) })
); );
@ -36,7 +37,7 @@ describe('useAPIErrorHandler', () => {
const message = result.current.formatAPIError( const message = result.current.formatAPIError(
new FetchError('Fetch Error Occured', { new FetchError('Fetch Error Occured', {
data: null, data: {
error: { error: {
name: 'ValidationError', name: 'ValidationError',
message: '', message: '',
@ -54,6 +55,7 @@ describe('useAPIErrorHandler', () => {
], ],
}, },
}, },
},
}) })
); );

View File

@ -35,10 +35,9 @@ const fetchBaseQuery = async <TData = unknown, TSend = unknown>({
* Default is GET. * Default is GET.
*/ */
const result = await get<TData>(url, config); const result = await get<TData>(url, config);
console.log('baseQuery', result);
return { data: result.data }; return { data: result.data };
} catch (error) { } catch (error) {
console.log('did we arrive here for some reason ?');
const err = error as FetchError; const err = error as FetchError;
/** /**
* Handle error of type FetchError * Handle error of type FetchError
@ -51,7 +50,7 @@ const fetchBaseQuery = async <TData = unknown, TSend = unknown>({
*/ */
return { return {
error: { error: {
status: err.response?.error.status, status: err.status,
code: err.code, code: err.code,
response: { response: {
data: err.response?.data, data: err.response?.data,

View File

@ -21,7 +21,7 @@ export interface UnknownApiError {
status?: number; status?: number;
} }
export type BaseQueryError = ApiError | UnknownApiError; export type BaseQueryError = ApiError | UnknownApiError | SerializedError;
const fetchBaseQuery = const fetchBaseQuery =
(): BaseQueryFn<string | QueryArguments, unknown, BaseQueryError> => (): BaseQueryFn<string | QueryArguments, unknown, BaseQueryError> =>
@ -95,8 +95,8 @@ const fetchBaseQuery =
error: { error: {
name: 'UnknownError', name: 'UnknownError',
message: 'There was an unknown error response from the API', message: 'There was an unknown error response from the API',
details: err.response?.data, details: err.response,
status: err.response?.error.status, status: err.status,
} as UnknownApiError, } as UnknownApiError,
}; };
} }
@ -114,7 +114,7 @@ const fetchBaseQuery =
} }
}; };
const isBaseQueryError = (error: BaseQueryError | SerializedError): error is BaseQueryError => { const isBaseQueryError = (error: BaseQueryError): error is ApiError | UnknownApiError => {
return error.name !== undefined; return error.name !== undefined;
}; };

View File

@ -21,7 +21,7 @@ export interface UnknownApiError {
status?: number; status?: number;
} }
export type BaseQueryError = ApiError | UnknownApiError; export type BaseQueryError = ApiError | UnknownApiError | SerializedError;
const fetchBaseQuery = const fetchBaseQuery =
(): BaseQueryFn<string | QueryArguments, unknown, BaseQueryError> => (): BaseQueryFn<string | QueryArguments, unknown, BaseQueryError> =>
@ -95,8 +95,8 @@ const fetchBaseQuery =
error: { error: {
name: 'UnknownError', name: 'UnknownError',
message: 'There was an unknown error response from the API', message: 'There was an unknown error response from the API',
details: err.response?.data, details: err.response,
status: err.response?.error.status, status: err.status,
} as UnknownApiError, } as UnknownApiError,
}; };
} }
@ -114,7 +114,7 @@ const fetchBaseQuery =
} }
}; };
const isBaseQueryError = (error: BaseQueryError | SerializedError): error is BaseQueryError => { const isBaseQueryError = (error: BaseQueryError): error is ApiError | UnknownApiError => {
return error.name !== undefined; return error.name !== undefined;
}; };