MCPcopy Create free account
hub / github.com/gotify/server / initAxios

Function initAxios

ui/src/apiAuth.ts:5–31  ·  view source on GitHub ↗
(currentUser: CurrentUser, snack: SnackReporter)

Source from the content-addressed store, hash-verified

3import {SnackReporter} from './snack/SnackManager';
4
5export const initAxios = (currentUser: CurrentUser, snack: SnackReporter) => {
6 axios.interceptors.request.use((config) => {
7 if (!config.headers.has('x-gotify-key')) {
8 config.headers['x-gotify-key'] = currentUser.token();
9 }
10 return config;
11 });
12
13 axios.interceptors.response.use(undefined, (error) => {
14 if (!error.response) {
15 snack('Gotify server is not reachable, try refreshing the page.');
16 return Promise.reject(error);
17 }
18
19 const status = error.response.status;
20
21 if (status === 401) {
22 currentUser.tryAuthenticate().then(() => snack('Could not complete request.'));
23 }
24
25 if (status === 400 || status === 403 || status === 500) {
26 snack(error.response.data.error + ': ' + error.response.data.errorDescription);
27 }
28
29 return Promise.reject(error);
30 });
31};

Callers 1

index.tsxFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…