From 01e3cd0296bba0ff4215ee7cb42c2411b64c50b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 17:22:20 +0100 Subject: [PATCH] fix notitle search and catch 404? --- .../pages/archivePage/archivePage.jsx | 28 ++++++++++++------- server/archive.api.js | 6 +--- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 31e2684b8..9228d1a33 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -100,8 +100,8 @@ const ArchivePage = createClass({ if(update === true) { this.updateStateWithForm(); }; - - try { + if (title !== '') { + try { this.setState({ searching: true, error: null }); const title = encodeURIComponent(this.state.title); @@ -117,6 +117,12 @@ const ArchivePage = createClass({ this.setState({ error: `${error.response.status}` }) this.updateStateWithBrews([], 1, 1, 0); } + console.log(!this.state.brewCollection || brewCollection.length === 0); + if(!this.state.brewCollection) { + this.setState({ error: '404'}); + } + } + }, renderNavItems : function () { @@ -253,8 +259,16 @@ const ArchivePage = createClass({ ); }; - if(title === '') {return (

Whenever you want, just start typing...

);} + + if(title === '') {return (

Whenever you want, just start typing...

);} + if (!brewCollection || brewCollection.length === 0) { + return ( +
+

No brews found

+
+ ); + }; if (error) { console.log('render Error: ', error); let errorMessage; @@ -277,13 +291,7 @@ const ArchivePage = createClass({ ); }; - if (!brewCollection || brewCollection.length === 0) { - return ( -
-

No brews found

-
- ); - }; + return (
diff --git a/server/archive.api.js b/server/archive.api.js index a7f545e79..fffe24497 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -41,7 +41,7 @@ const archive = { .maxTimeMS(5000) .exec(); - const totalBrews = await HomebrewModel.countDocuments(titleQuery, projection); + const totalBrews = await HomebrewModel.countDocuments(titleQuery, projection).maxTimeMS(5000); const totalPages = Math.ceil(totalBrews / pageSize); //console.log('Total brews: ', totalBrews); @@ -49,10 +49,6 @@ const archive = { return res.json({ brews, page, totalPages, totalBrews}); } catch (error) { console.error(error); - console.log(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) { return res.status(503).json({ errorCode: '503', message: 'Service Unavailable' }); } else {