mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 22:52:39 +00:00
more error handling
This commit is contained in:
@@ -214,7 +214,6 @@ const ArchivePage = createClass({
|
|||||||
const title = encodeURIComponent(this.state.title);
|
const title = encodeURIComponent(this.state.title);
|
||||||
const size = parseInt(this.state.pageSize);
|
const size = parseInt(this.state.pageSize);
|
||||||
const {page, totalPages, legacy, v3} = this.state;
|
const {page, totalPages, legacy, v3} = this.state;
|
||||||
console.log('page: ', page);
|
|
||||||
const pages = new Array(totalPages).fill().map((_, index) => (
|
const pages = new Array(totalPages).fill().map((_, index) => (
|
||||||
<a key={index} className={`pageNumber ${page == index + 1 ? 'currentPage' : ''}`} href={`/archive?title=${title}&page=${index+1}&size=${size}&v3=${v3}&legacy=${legacy}`}>{index + 1}</a>
|
<a key={index} className={`pageNumber ${page == index + 1 ? 'currentPage' : ''}`} href={`/archive?title=${title}&page=${index+1}&size=${size}&v3=${v3}&legacy=${legacy}`}>{index + 1}</a>
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -40,15 +40,6 @@ const archive = {
|
|||||||
.limit(pageSize)
|
.limit(pageSize)
|
||||||
.maxTimeMS(5000)
|
.maxTimeMS(5000)
|
||||||
.exec();
|
.exec();
|
||||||
//console.log(brews.length);
|
|
||||||
|
|
||||||
if(!brews || brews.length === 0) {
|
|
||||||
// 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 totalBrews = await HomebrewModel.countDocuments(titleQuery, projection);
|
||||||
|
|
||||||
@@ -58,6 +49,9 @@ const archive = {
|
|||||||
return res.json({ brews, page, totalPages, totalBrews});
|
return res.json({ brews, page, totalPages, totalBrews});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
if (error.response && error.response.status === 404) {
|
||||||
|
return res.status(404).json({ errorCode: '404', message: 'Brews not found' });
|
||||||
|
}
|
||||||
if (error.response && error.response.status === 503) {
|
if (error.response && error.response.status === 503) {
|
||||||
return res.status(503).json({ errorCode: '503', message: 'Service Unavailable' });
|
return res.status(503).json({ errorCode: '503', message: 'Service Unavailable' });
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user