added post map interceptor

This commit is contained in:
Fedor Katurov 2021-04-20 16:39:51 +07:00
parent fda24c78b0
commit 9c436d348c
5 changed files with 33 additions and 29 deletions

View file

@ -64,21 +64,4 @@ steps:
- cp -a $${ENV_PATH}/${DRONE_BRANCH}/. $${BUILD_PATH}/${DRONE_BRANCH} - cp -a $${ENV_PATH}/${DRONE_BRANCH}/. $${BUILD_PATH}/${DRONE_BRANCH}
- docker-compose build - docker-compose build
- docker-compose up -d - docker-compose up -d
# - name: telgram_notify
# image: appleboy/drone-telegram
# when:
# status:
# - success
# - failure
# settings:
# token:
# from_secret: telegram_token
# to:
# from_secret: telegram_chat_id
# format: markdown
# message: >
# {{#success build.status}}🤓{{else}}😨{{/success}}
# [{{repo.name}} / {{commit.branch}}]({{ build.link }})
# ```
# {{ commit.message }}
# ```

View file

@ -69,13 +69,13 @@ export function configureStore(): { store: Store<any>; persistor: Persistor } {
// Pass token to axios // Pass token to axios
api.interceptors.request.use(options => { api.interceptors.request.use(options => {
const token = store.getState().user.token; const token = store.getState().user.user.token;
if (!token) { if (!token) {
return options; return options;
} }
return assocPath(['headers', 'authorization'], `Bearer ${token}`, options); return assocPath(['headers', 'authorization'], token, options);
}); });
// Logout on 401 // Logout on 401

View file

@ -6,6 +6,8 @@ import { LatLngLiteral } from 'leaflet';
import { IRoute } from '~/redux/map/types'; import { IRoute } from '~/redux/map/types';
import { INominatimResult } from '~/redux/types'; import { INominatimResult } from '~/redux/types';
import { api } from './instance'; import { api } from './instance';
import { postMapInterceptor } from '~/utils/api/interceptors';
import { PostMapRequest, PostMapResponse } from '~/utils/api/types';
interface IGetRouteList { interface IGetRouteList {
min: number; min: number;
@ -62,15 +64,9 @@ export const postMap = ({
provider, provider,
is_public, is_public,
description, description,
}: Partial<IRoute> & { }: PostMapRequest) =>
force: boolean;
}) =>
api api
.post<{ .post<PostMapResponse>(
route: IRoute;
error?: string;
code?: string;
}>(
API.POST_MAP, API.POST_MAP,
{ {
route: { route: {
@ -86,7 +82,7 @@ export const postMap = ({
}, },
force, force,
}, },
); ).catch(postMapInterceptor);
export const checkIframeToken = ({ export const checkIframeToken = ({
viewer_id, viewer_id,

View file

@ -0,0 +1,14 @@
import { AxiosError } from 'axios';
import { PostMapResponse } from '~/utils/api/types';
export const postMapInterceptor = (res: AxiosError<PostMapResponse>) => {
if (res.response?.data.code) {
return res.response;
}
if (res.response?.data.error) {
throw new Error(res.response?.data.error);
}
throw res;
};

11
src/utils/api/types.ts Normal file
View file

@ -0,0 +1,11 @@
import { IRoute } from '~/redux/map/types';
export interface PostMapResponse {
route: IRoute;
error?: string;
code?: string;
}
export type PostMapRequest = Partial<IRoute> & {
force: boolean;
}