-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: axios base query with retry; error handling; qr-code scan
- Loading branch information
1 parent
ea5e0cf
commit ab74759
Showing
27 changed files
with
223 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './constants'; | ||
export * from './logging'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { BaseQueryFn } from '@reduxjs/toolkit/query'; | ||
import axios, { AxiosError, AxiosRequestConfig } from 'axios'; | ||
import { RootState } from '@store'; | ||
|
||
const axiosInstance = axios.create({}); | ||
|
||
export const axiosBaseQuery = | ||
(): BaseQueryFn< | ||
{ | ||
url: string; | ||
method?: AxiosRequestConfig['method']; | ||
body?: AxiosRequestConfig['data']; | ||
params?: AxiosRequestConfig['params']; | ||
headers?: AxiosRequestConfig['headers']; | ||
}, | ||
unknown, | ||
unknown | ||
> => | ||
async ({ url, method, body: data, params, headers }, { getState }) => { | ||
try { | ||
const baseUrl = (getState() as RootState).config.url; | ||
const result = await axiosInstance({ | ||
url: baseUrl + url, | ||
method, | ||
data, | ||
params, | ||
headers, | ||
}); | ||
return { data: JSON.parse(result.data) }; | ||
} catch (error) { | ||
if (error instanceof SyntaxError) { | ||
return { | ||
error: { | ||
status: 500, | ||
data: error.message, | ||
}, | ||
}; | ||
} | ||
if (error instanceof AxiosError) { | ||
return { | ||
error: { | ||
status: error.response?.status, | ||
data: error.response?.data || error.message, | ||
}, | ||
}; | ||
} | ||
return { | ||
error, | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createApi, retry } from '@reduxjs/toolkit/query/react'; | ||
import { axiosBaseQuery } from './axios-base.ts'; | ||
|
||
// initialize an empty api service that we'll inject endpoints into later as needed | ||
export const emptySplitApi = createApi({ | ||
baseQuery: retry(axiosBaseQuery(), { | ||
maxRetries: 3, | ||
}), | ||
endpoints: () => ({}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './empty.api.ts'; | ||
export * from './gen/files.api.gen.ts'; | ||
export * from './gen/scans.api.gen.ts'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import { createSelector } from '@reduxjs/toolkit'; | ||
import { RootState } from './types.ts'; | ||
import { RootState } from '@store/types.ts'; | ||
|
||
export const selectNotification = createSelector( | ||
(ro: RootState) => ro.notification.messages, | ||
(p) => p.filter(({ message }) => message.length > 0) | ||
); | ||
export const selectConfigUrl = createSelector( | ||
(ro: RootState) => ro.config, | ||
({ url }) => url | ||
); |
Oops, something went wrong.