Skip to content

Commit

Permalink
add transformError to dataLibraryApi
Browse files Browse the repository at this point in the history
  • Loading branch information
craigrbarnes committed Dec 6, 2024
1 parent 26ee3cb commit 317816d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
30 changes: 30 additions & 0 deletions packages/core/src/features/dataLibrary/dataLibraryApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export const dataLibraryApi = dataLibraryTags.injectEndpoints({
transformResponse: (res: DataLibraryAPIResponse) => {
return { lists: BuildLists(res) };
},
transformErrorResponse(response) {
if ('originalStatus' in response)
return { status: response.originalStatus, data: response.data };
return response;
},
}),
getDataLibraryList: builder.query<Datalist, string>({
query: (id: string) => `${GEN3_DATA_LIBRARY_API}/${id}`,
Expand All @@ -45,13 +50,23 @@ export const dataLibraryApi = dataLibraryTags.injectEndpoints({
body: lists,
}),
invalidatesTags: [TAGS],
transformErrorResponse(response) {
if ('originalStatus' in response)
return { status: response.originalStatus, data: response.data };
return response;
},
}),
addDataLibraryList: builder.mutation<void, Partial<Datalist> | undefined>({
query: (list) => ({
url: `${GEN3_DATA_LIBRARY_API}/${nanoid()}`,
method: 'POST',
body: list ?? {},
}),
transformErrorResponse(response) {
if ('originalStatus' in response)
return { status: response.originalStatus, data: response.data };
return response;
},
invalidatesTags: [TAGS],
}),
updateDataLibraryList: builder.mutation<void, AddUpdateListParams>({
Expand All @@ -60,20 +75,35 @@ export const dataLibraryApi = dataLibraryTags.injectEndpoints({
method: 'PUT',
body: list,
}),
transformErrorResponse(response) {
if ('originalStatus' in response)
return { status: response.originalStatus, data: response.data };
return response;
},
invalidatesTags: [TAGS],
}),
deleteDataLibraryList: builder.mutation<void, string>({
query: (id) => ({
url: `${GEN3_DATA_LIBRARY_API}/${id}`,
method: 'DELETE',
}),
transformErrorResponse(response) {
if ('originalStatus' in response)
return { status: response.originalStatus, data: response.data };
return response;
},
invalidatesTags: [TAGS],
}),
deleteAllDataLibrary: builder.mutation<void, void>({
query: () => ({
url: `${GEN3_DATA_LIBRARY_API}`,
method: 'DELETE',
}),
transformErrorResponse(response) {
if ('originalStatus' in response)
return { status: response.originalStatus, data: response.data };
return response;
},
invalidatesTags: [TAGS],
}),
}),
Expand Down
10 changes: 8 additions & 2 deletions packages/frontend/src/features/DataLibrary/DataLibraryLists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ const DataLibraryLists: React.FC<DataLibraryConfig> = ({
};

if (isError) {
console.log('dataLibraryError', dataLibraryError);
let message = 'There was a error getting the library';
if (dataLibraryError?.status in HTTPUserFriendlyErrorMessages) {
message = HTTPUserFriendlyErrorMessages[dataLibraryError?.status];
if (
dataLibraryError &&
'data' in dataLibraryError &&
dataLibraryError?.status in HTTPUserFriendlyErrorMessages
) {
message =
HTTPUserFriendlyErrorMessages[dataLibraryError?.status as number];
}
return (
<div className="flex flex-col w-full ml-2">
Expand Down

0 comments on commit 317816d

Please sign in to comment.