- Add ErrorBoundary component for React error handling - Create animated error pages (403, 404, 500, 502, 503) - Implement ErrorAnimation component with seven-segment display - Add apiClient (axios) and apiFetch (fetch) wrappers with automatic error page redirects - Migrate critical API calls to use new error handling - Update font from Roboto to Open Sans across all components - Remove unused CLIENT_URL from docker-compose files - Rename 404Page.css to ErrorPage.css for consistency - Add comprehensive ERROR_HANDLING.md documentation
38 lines
829 B
JavaScript
38 lines
829 B
JavaScript
import apiClient from './apiClient'
|
|
|
|
//import swal from 'sweetalert';
|
|
import Swal from 'sweetalert2/dist/sweetalert2.js'
|
|
|
|
|
|
export async function sendRequest(file, handleLoading, handleResponse) {
|
|
if (file === undefined || !file.name.match(/.(jpg|jpeg|png|gif)$/i)){
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Oops...',
|
|
text: 'Seems like you didn\'t submit an image.',
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
const formData = new FormData()
|
|
formData.append("file", file)
|
|
|
|
// Change loading state in root component
|
|
handleLoading()
|
|
|
|
try {
|
|
const res = await apiClient.post('/upload', formData, {
|
|
headers: {
|
|
"Content-Type": "multipart/form-data"
|
|
}
|
|
})
|
|
|
|
handleResponse(res)
|
|
|
|
}
|
|
catch(err) {
|
|
console.error(err);
|
|
}
|
|
}
|
|
|