mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-27 15:52:39 +00:00
proper error handling(i think)
This commit is contained in:
@@ -243,27 +243,8 @@ const ArchivePage = createClass({
|
||||
|
||||
renderFoundBrews() {
|
||||
const { title, brewCollection, page, totalPages, error, searching } = this.state;
|
||||
if(searching === false && title === '' && error === null) {return (<div className='foundBrews noBrews'><h3>Whenever you want, just start typing...</h3></div>);}
|
||||
|
||||
if(searching === false && error === 'Error: Service Unavailable') {
|
||||
return (
|
||||
<div className='foundBrews noBrews'>
|
||||
<div><h3>I'm sorry, your request didn't work</h3>
|
||||
<br /><p>Your search is not specific enough. Too many brews meet this criteria for us to display them.</p>
|
||||
</div></div>
|
||||
);
|
||||
};
|
||||
console.log(searching, !brewCollection, error);
|
||||
console.log('404: ', searching === false && (!brewCollection || error === 'Error: Not found'))
|
||||
if(searching === false && (!brewCollection || error === 'Error: Not found')) {
|
||||
return (
|
||||
<div className='foundBrews noBrews'>
|
||||
<h3>We haven't found brews meeting your request.</h3>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
if(searching === true) {
|
||||
|
||||
if(searching) {
|
||||
return (
|
||||
<div className='foundBrews searching'>
|
||||
<span><h3>Searching</h3><h3 className='searchAnim'>...</h3></span>
|
||||
@@ -271,6 +252,37 @@ const ArchivePage = createClass({
|
||||
);
|
||||
};
|
||||
|
||||
if(title === '') {return (<div className='foundBrews noBrews'><h3>Whenever you want, just start typing...</h3></div>);}
|
||||
|
||||
if (error) {
|
||||
let errorMessage;
|
||||
switch (error.errorCode) {
|
||||
case '404':
|
||||
errorMessage = "We didn't find any brew";
|
||||
break;
|
||||
case '503':
|
||||
errorMessage = 'Your search is not specific enough. Too many brews meet this criteria for us to display them.';
|
||||
break;
|
||||
case '500':
|
||||
default:
|
||||
errorMessage = 'An unexpected error occurred';
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='foundBrews noBrews'>
|
||||
<h3>Error: {errorMessage}</h3>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
if (!brewCollection || brewCollection.length === 0) {
|
||||
return (
|
||||
<div className='foundBrews noBrews'>
|
||||
<h3>No brews found</h3>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='foundBrews'>
|
||||
<span className='totalBrews'>Brews found: {this.state.totalBrews}</span>
|
||||
|
||||
@@ -46,6 +46,10 @@ const archive = {
|
||||
// No published documents found with the given title
|
||||
return res.status(404).json({ error: 'Published documents not found' });
|
||||
}
|
||||
if (!brews || brews.length === 0) {
|
||||
return res.status(404).json({ errorCode: '404', message: 'Published documents not found' });
|
||||
}
|
||||
|
||||
const totalBrews = await HomebrewModel.countDocuments(titleQuery, projection);
|
||||
|
||||
const totalPages = Math.ceil(totalBrews / pageSize);
|
||||
@@ -54,7 +58,11 @@ const archive = {
|
||||
return res.json({ brews, page, totalPages, totalBrews});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({ error: 'Internal Server Error' });
|
||||
if (error.response && error.response.status === 503) {
|
||||
return res.status(503).json({ errorCode: '503', message: 'Service Unavailable' });
|
||||
} else {
|
||||
return res.status(500).json({ errorCode: '500', message: 'Internal Server Error' });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user