mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
attaching accounts and displaying errors
This commit is contained in:
parent
3ae22fb63d
commit
b1c71faf3a
9 changed files with 140 additions and 18 deletions
|
@ -4,7 +4,7 @@ import { API } from '~/constants/api';
|
|||
import { store } from '~/redux/store';
|
||||
import { IResultWithStatus } from '~/redux/types';
|
||||
|
||||
export const authMiddleware = (r) => {
|
||||
export const authMiddleware = r => {
|
||||
store.dispatch(push('/login'));
|
||||
return r;
|
||||
};
|
||||
|
@ -23,26 +23,27 @@ export const HTTP_RESPONSES = {
|
|||
TOO_MANY_REQUESTS: 429,
|
||||
};
|
||||
|
||||
export const resultMiddleware = (<T extends {}>({
|
||||
export const resultMiddleware = <T extends {}>({
|
||||
status,
|
||||
data,
|
||||
}: {
|
||||
status: number;
|
||||
data: T;
|
||||
}): { status: number; data: T } => ({ status, data }));
|
||||
}): { status: number; data: T } => ({ status, data });
|
||||
|
||||
export const errorMiddleware = <T extends any>(debug): IResultWithStatus<T> => (debug && debug.response
|
||||
? debug.response
|
||||
: {
|
||||
status: HTTP_RESPONSES.CONNECTION_REFUSED,
|
||||
data: {},
|
||||
debug,
|
||||
error: 'Ошибка сети',
|
||||
});
|
||||
export const errorMiddleware = <T extends any>(debug): IResultWithStatus<T> =>
|
||||
debug && debug.response
|
||||
? debug.response.data || debug.response
|
||||
: {
|
||||
status: HTTP_RESPONSES.CONNECTION_REFUSED,
|
||||
data: {},
|
||||
debug,
|
||||
error: 'Ошибка сети',
|
||||
};
|
||||
|
||||
export const configWithToken = (
|
||||
access: string,
|
||||
config: AxiosRequestConfig = {},
|
||||
config: AxiosRequestConfig = {}
|
||||
): AxiosRequestConfig => ({
|
||||
...config,
|
||||
headers: { ...(config.headers || {}), Authorization: `Bearer ${access}` },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue