0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-29 06:52:41 +00:00

Merge pull request #2105 from jeddai/add-async-handler

add asyncHandler to async methods in routes
This commit is contained in:
Trevor Buckner
2022-03-29 16:43:00 -04:00
committed by GitHub
3 changed files with 44 additions and 43 deletions

View File

@@ -276,26 +276,26 @@ const EditPage = createClass({
console.log(errMsg); console.log(errMsg);
} catch (e){} } catch (e){}
if(this.state.errors.status == '401'){ // if(this.state.errors.status == '401'){
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={this.clearErrors}> // <div className='errorContainer' onClick={this.clearErrors}>
You must be signed in to a Google account // You must be signed in to a Google account
to save this to<br />Google Drive!<br /> // to save this to<br />Google Drive!<br />
<a target='_blank' rel='noopener noreferrer' // <a target='_blank' rel='noopener noreferrer'
href={`https://www.naturalcrit.com/login?redirect=${this.state.url}`}> // href={`https://www.naturalcrit.com/login?redirect=${this.state.url}`}>
<div className='confirm'> // <div className='confirm'>
Sign In // Sign In
</div> // </div>
</a> // </a>
<div className='deny'> // <div className='deny'>
Not Now // Not Now
</div> // </div>
</div> // </div>
</Nav.item>; // </Nav.item>;
} // }
if(this.state.errors.response.req.url.match(/^\/api\/.*Google.*$/m)){ if(this.state.errors.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'>
Oops! Oops!
<div className='errorContainer' onClick={this.clearErrors}> <div className='errorContainer' onClick={this.clearErrors}>

View File

@@ -187,26 +187,26 @@ const NewPage = createClass({
console.log(errMsg); console.log(errMsg);
} catch (e){} } catch (e){}
if(this.state.errors.status == '401'){ // if(this.state.errors.status == '401'){
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={this.clearErrors}> // <div className='errorContainer' onClick={this.clearErrors}>
You must be signed in to a Google account // You must be signed in to a Google account
to save this to<br />Google Drive!<br /> // to save this to<br />Google Drive!<br />
<a target='_blank' rel='noopener noreferrer' // <a target='_blank' rel='noopener noreferrer'
href={`https://www.naturalcrit.com/login?redirect=${this.state.url}`}> // href={`https://www.naturalcrit.com/login?redirect=${this.state.url}`}>
<div className='confirm'> // <div className='confirm'>
Sign In // Sign In
</div> // </div>
</a> // </a>
<div className='deny'> // <div className='deny'>
Not Now // Not Now
</div> // </div>
</div> // </div>
</Nav.item>; // </Nav.item>;
} // }
if(this.state.errors.response.req.url.match(/^\/api\/.*Google.*$/m)){ if(this.state.errors.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'>
Oops! Oops!
<div className='errorContainer' onClick={this.clearErrors}> <div className='errorContainer' onClick={this.clearErrors}>

View File

@@ -5,6 +5,7 @@ const zlib = require('zlib');
const GoogleActions = require('./googleActions.js'); const GoogleActions = require('./googleActions.js');
const Markdown = require('../shared/naturalcrit/markdown.js'); const Markdown = require('../shared/naturalcrit/markdown.js');
const yaml = require('js-yaml'); const yaml = require('js-yaml');
const asyncHandler = require('express-async-handler');
// const getTopBrews = (cb) => { // const getTopBrews = (cb) => {
// HomebrewModel.find().sort({ views: -1 }).limit(5).exec(function(err, brews) { // HomebrewModel.find().sort({ views: -1 }).limit(5).exec(function(err, brews) {
@@ -226,10 +227,10 @@ const deleteGoogleBrew = async (account, id, res)=>{
return true; return true;
}; };
router.post('/api', newBrew); router.post('/api', asyncHandler(newBrew));
router.put('/api/:id', updateBrew); router.put('/api/:id', asyncHandler(updateBrew));
router.put('/api/update/:id', updateBrew); router.put('/api/update/:id', asyncHandler(updateBrew));
router.delete('/api/:id', deleteBrew); router.delete('/api/:id', asyncHandler(deleteBrew));
router.get('/api/remove/:id', deleteBrew); router.get('/api/remove/:id', asyncHandler(deleteBrew));
module.exports = router; module.exports = router;