Skip to content

Commit

Permalink
cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
erka committed Nov 26, 2023
1 parent 788352d commit 3966d5e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
25 changes: 3 additions & 22 deletions ui/src/app/segments/segmentsApi.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { apiURL, checkResponse, defaultHeaders } from '~/data/api';
import { createApi } from '@reduxjs/toolkit/query/react';
import { IConstraintBase } from '~/types/Constraint';
import { ISegment, ISegmentBase, ISegmentList } from '~/types/Segment';

type CustomFetchFn = (
url: RequestInfo,
options: RequestInit | undefined
) => Promise<Response>;

const customFetchFn: CustomFetchFn = async (url, options) => {
const headers = defaultHeaders();

const response = await fetch(url, {
...options,
headers
});
checkResponse(response);
return response;
};
import { baseQuery } from '~/utils/redux-rtk';

export const segmentsApi = createApi({
reducerPath: 'segments',
baseQuery: fetchBaseQuery({
baseUrl: apiURL,
fetchFn: customFetchFn
}),
baseQuery,
tagTypes: ['Segment'],
endpoints: (builder) => ({
// get list of segments in this namespace
Expand Down
1 change: 1 addition & 0 deletions ui/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function isFetchBaseQueryError(error: unknown): error is ErrorWithMessage {
typeof error === 'object' &&
error !== null &&
'data' in error &&
error.data !== null &&
typeof (error.data as Record<string, unknown>).message === 'string'
);
}
Expand Down
23 changes: 23 additions & 0 deletions ui/src/utils/redux-rtk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { apiURL, checkResponse, defaultHeaders } from '~/data/api';

type CustomFetchFn = (
url: RequestInfo,
options: RequestInit | undefined
) => Promise<Response>;

const customFetchFn: CustomFetchFn = async (url, options) => {
const headers = defaultHeaders();

const response = await fetch(url, {
...options,
headers
});
checkResponse(response);
return response;
};

export const baseQuery = fetchBaseQuery({
baseUrl: apiURL,
fetchFn: customFetchFn
});

0 comments on commit 3966d5e

Please sign in to comment.