0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-08 18:22:40 +00:00

Add custom error messages.

This commit is contained in:
Trevor Buckner
2024-01-18 17:20:31 -05:00
parent a241813b8d
commit b0ea34cc3f
2 changed files with 40 additions and 6 deletions

View File

@@ -21,10 +21,11 @@ const ErrorNavItem = createClass({
this.props.parent.setState(state); this.props.parent.setState(state);
}; };
const error = this.props.error; const error = this.props.error;
const response = error.response; const response = error.response;
const status = response.status; const status = response.status;
const message = response.body?.message; const HBErrorCode = response.body?.HBErrorCode;
const message = response.body?.message;
let errMsg = ''; let errMsg = '';
try { try {
errMsg += `${error.toString()}\n\n`; errMsg += `${error.toString()}\n\n`;
@@ -40,7 +41,9 @@ const ErrorNavItem = createClass({
{message ?? 'Conflict: please refresh to get latest changes'} {message ?? 'Conflict: please refresh to get latest changes'}
</div> </div>
</Nav.item>; </Nav.item>;
} else if(status === 412) { }
if(status === 412) {
return <Nav.item className='save error' icon='fas fa-exclamation-triangle'> return <Nav.item className='save error' icon='fas fa-exclamation-triangle'>
Oops! Oops!
<div className='errorContainer' onClick={clearError}> <div className='errorContainer' onClick={clearError}>
@@ -48,6 +51,36 @@ const ErrorNavItem = createClass({
</div> </div>
</Nav.item>; </Nav.item>;
} }
if(HBErrorCode === '04') {
return <Nav.item className='save error' icon='fas fa-exclamation-triangle'>
Oops!
<div className='errorContainer' onClick={clearError}>
You are no longer signed in as an author of
this brew! Were you signed out from a different
window? Visit our log in page, then try again!
<br></br>
<a target='_blank' rel='noopener noreferrer'
href={`https://www.naturalcrit.com/login?redirect=${window.location.href}`}>
<div className='confirm'>
Sign In
</div>
</a>
<div className='deny'>
Not Now
</div>
</div>
</Nav.item>;
}
if(response.body?.errors?.[0].reason == 'storageQuotaExceeded') {
return <Nav.item className='save error' icon='fas fa-exclamation-triangle'>
Oops!
<div className='errorContainer' onClick={clearError}>
Can't save because your Google Drive seems to be full!
</div>
</Nav.item>;
}
if(response.req.url.match(/^\/api.*Google.*$/m)){ if(response.req.url.match(/^\/api.*Google.*$/m)){
return <Nav.item className='save error' icon='fas fa-exclamation-triangle'> return <Nav.item className='save error' icon='fas fa-exclamation-triangle'>
@@ -57,6 +90,7 @@ const ErrorNavItem = createClass({
expired! Visit our log in page to sign out expired! Visit our log in page to sign out
and sign back in with Google, and sign back in with Google,
then try saving again! then try saving again!
<br></br>
<a target='_blank' rel='noopener noreferrer' <a target='_blank' rel='noopener noreferrer'
href={`https://www.naturalcrit.com/login?redirect=${window.location.href}`}> href={`https://www.naturalcrit.com/login?redirect=${window.location.href}`}>
<div className='confirm'> <div className='confirm'>

View File

@@ -477,7 +477,7 @@ app.use(async (err, req, res, next)=>{
if(err.originalUrl?.startsWith('/api/')) { if(err.originalUrl?.startsWith('/api/')) {
// console.log('API error'); // console.log('API error');
res.status(err.status || err.response?.status || 500).send(err.message || err); res.status(err.status || err.response?.status || 500).send(err);
return; return;
} }