-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fully functioning error handling on both client and serverside
- Loading branch information
1 parent
ea9aa54
commit 97e5eea
Showing
4 changed files
with
89 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function catchErrors(error, displayError) { | ||
let errorMsg; | ||
const {response, request} = error; | ||
if (response) { | ||
//req was made and server responded with a status code that is not 2XX range | ||
errorMsg = response.data; | ||
console.error("Error response", errorMsg); | ||
|
||
// For cloudinary image upload error | ||
if (response.data.error) { | ||
errorMsg = response.data.error.message; | ||
} | ||
} else if (request) { | ||
// req was made but no response was returned | ||
errorMsg = request; | ||
console.error("Error Request", errorMsg); | ||
} else { | ||
// something else went wrong | ||
errorMsg = message; | ||
console.error("Error", errorMsg); | ||
} | ||
|
||
displayError(errorMsg); | ||
|
||
|
||
} | ||
|
||
export default catchErrors; |