Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled server error response handler #41

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const serverMethods = require('../helpers/server-methods');
const slack = require('../helpers/slack');
const resetScript = require('../scripts/reset');
const logger = require('../helpers/logger');
const errorResponse = require('../responses/errorResponse');

const { app: appConfig } = require('../config');

Expand Down Expand Up @@ -93,8 +94,7 @@ module.exports = {
data: playlist,
});
} catch (err) {
logger.error(err);
return res.status(500).send({ message: 'An error occurred' });
return errorResponse(res, err);
}
},

Expand Down
7 changes: 3 additions & 4 deletions controllers/playlist.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const spotify = require('../helpers/spotify');
const logger = require('../helpers/logger');
const errorResponse = require('../responses/errorResponse');

module.exports = {

Expand All @@ -19,8 +19,7 @@ module.exports = {
data: playlist,
});
} catch (err) {
logger.error(err);
return res.status(500).send({ status: false, message: 'An error occurred' });
return errorResponse(res, err);
}
},

Expand All @@ -32,7 +31,7 @@ module.exports = {
data: playlists,
});
} catch (err) {
return res.status(500).send({ status: false, message: 'An error occurred' });
return errorResponse(res, err);
}
},
};
7 changes: 3 additions & 4 deletions controllers/track.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const spotify = require('../helpers/spotify');
const logger = require('../helpers/logger');
const errorResponse = require('../responses/errorResponse');

module.exports = {

Expand All @@ -14,8 +14,7 @@ module.exports = {
data: trackFeatures,
});
} catch (err) {
logger.error(err);
return res.status(500).send({ message: 'An error occurred' });
return errorResponse(res, err);
}
},

Expand All @@ -35,7 +34,7 @@ module.exports = {
data,
});
} catch (err) {
return res.status(500).send({ message: 'An error occurred' });
return errorResponse(res, err);
}
},
};
8 changes: 8 additions & 0 deletions responses/errorResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const logger = require('../helpers/logger');

const errorResponse = (res, err) => {
logger.error(err);
moyo-paystack marked this conversation as resolved.
Show resolved Hide resolved
return res.status(500).send({ success: false, message: 'An error occurred' });
};

module.exports = errorResponse;