Skip to content

Commit

Permalink
feat(upload): handle backend responses (if any)
Browse files Browse the repository at this point in the history
  • Loading branch information
devshred committed Feb 16, 2024
1 parent 3f81fbf commit bd92c2e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/context/UploadContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ export const UploadProvider: React.FC<UploadProviderType> = ({ children }) => {
.then((response) =>
setUploadedFiles((prevState) => [...prevState, response.data[0]])
)
.catch(() => setError('Failed to upload files. Sorry!'))
.catch((error) => {
if (error.code === 'ERR_NETWORK') {
setError('The backend server is not available at the moment. Sorry!')
} else if (error.code === 'ERR_BAD_REQUEST') {
setError("Couldn't process some files. Was it really GPS data?")
} else {
setError('Failed to upload files. Sorry!')
}
})
.finally(() => setLoading(false))
}

Expand Down

0 comments on commit bd92c2e

Please sign in to comment.