Create event with API and load event details
This commit is contained in:
parent
855477570f
commit
8e5954e0ca
19 changed files with 349 additions and 58 deletions
45
crabfit-frontend/src/services/index.js
Normal file
45
crabfit-frontend/src/services/index.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import axios from 'axios';
|
||||
|
||||
export const instance = axios.create({
|
||||
baseURL: 'http://localhost:8080',
|
||||
timeout: 1000 * 300,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
const handleError = error => {
|
||||
if (error.response && error.response.status) {
|
||||
console.log('[Error handler] res:', error.response);
|
||||
}
|
||||
return Promise.reject(error);
|
||||
};
|
||||
|
||||
const api = {
|
||||
get: async (endpoint, data = {}) => {
|
||||
try {
|
||||
const response = await instance.get(endpoint, { params: data });
|
||||
return Promise.resolve(response);
|
||||
} catch (error) {
|
||||
return handleError(error);
|
||||
}
|
||||
},
|
||||
post: async (endpoint, data, options = {}) => {
|
||||
try {
|
||||
const response = await instance.post(endpoint, data, options);
|
||||
return Promise.resolve(response);
|
||||
} catch (error) {
|
||||
return handleError(error);
|
||||
}
|
||||
},
|
||||
patch: async (endpoint, data) => {
|
||||
try {
|
||||
const response = await instance.patch(endpoint, data);
|
||||
return Promise.resolve(response);
|
||||
} catch (error) {
|
||||
return handleError(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default api;
|
||||
Loading…
Add table
Add a link
Reference in a new issue