interceptor error types needed

This commit is contained in:
ntr committed 2022-08-14 22:56:46 +10:00
1 parent b0bca74ee2
commit 7121b2f4cd
4 files changed
+29 -24

No files matched your search

+14 -19
View File
@@ -1,53 +1,48 @@
import axios from 'axios';
import type { AxiosInstance } from 'axios';
const api = axios.create({
baseURL: 'http://localhost:41337',
withCredentials: true
});
// Add a response interceptor
api.interceptors.response.use(function onSuccess(response) {
return [null, response.data];
}, function onError(error) {
return [error.response.data.error, null];
});
const actions = {
getBundles: async function getBundles() {
const { data: bundles } = await api.get('/bundles');
return bundles;
return api.get('/bundles');
},
getUserOffers: async function getUserOffers(state, userId) {
const { data: offers } = await api.get(`/user/${userId}/offers`);
return offers;
return api.get(`/user/${userId}/offers`);
},
getOffers: async function getOffers(userId) {
const { data } = await api.get(`/user/${userId}/offers`);
return data;
return api.get(`/user/${userId}/offers`);
},
getLogin: async function getLogin() {
try {
const { data: user } = await api.get('/auth/login')
console.log(user);
return user;
} catch (e) {
return null;
}
return api.get('/auth/login')
},
postLogin: async function postLogin(email, password) {
const { data } = await api.post('/auth/login', {
return api.post('/auth/login', {
email,
password,
// discogs,
});
return data;
},
postRegister: async function postRegister(email, password) {
const { data } = await api.post('/auth/register', {
return api.post('/auth/register', {
email,
password,
});
return data;
},
};