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

Use constants instead of number literals for http status codes #5276

Merged
merged 1 commit into from
Dec 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 5 additions & 3 deletions lib/api/notifications-api.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
'use strict';

var consts = require('../constants');

function configure (app, wares, ctx) {
var express = require('express')
, api = express.Router( )
;

api.post('/notifications/pushovercallback', function (req, res) {
if (ctx.pushnotify.pushoverAck(req.body)) {
res.sendStatus(200);
res.sendStatus(consts.HTTP_OK);
} else {
res.sendStatus(500);
res.sendStatus(consts.HTTP_INTERNAL_ERROR);
}
});

Expand All @@ -21,7 +23,7 @@ function configure (app, wares, ctx) {
var time = req.query.time && Number(req.query.time);
console.info('got api ack, level: ', level, ', time: ', time, ', query: ', req.query);
ctx.notifications.ack(level, group, time, true);
res.sendStatus(200);
res.sendStatus(consts.HTTP_OK);
});
}

Expand Down
6 changes: 4 additions & 2 deletions lib/api/notifications-v2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var consts = require('../constants');

function configure (app, ctx) {
var express = require('express')
, api = express.Router( )
Expand All @@ -8,10 +10,10 @@ function configure (app, ctx) {
api.post('/loop', ctx.authorization.isPermitted('notifications:loop:push'), function (req, res) {
ctx.loop.sendNotification(req.body, req.connection.remoteAddress, function (error) {
if (error) {
res.status(500).send(error)
res.status(consts.HTTP_INTERNAL_ERROR).send(error)
console.log("error sending notification to Loop: ", error);
} else {
res.sendStatus(200);
res.sendStatus(consts.HTTP_OK);
}
});
});
Expand Down
6 changes: 3 additions & 3 deletions lib/api3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ function configure (env, ctx) {
limit: 1048576 * 50
}), function errorHandler (err, req, res, next) {
console.error(err);
res.status(500).json({
status: 500,
res.status(apiConst.HTTP.INTERNAL_ERROR).json({
status: apiConst.HTTP.INTERNAL_ERROR,
message: apiConst.MSG.HTTP_500_INTERNAL_ERROR
});
if (next) { // we need 4th parameter next to behave like error handler, but we have to use it to prevent "unused variable" message
Expand Down Expand Up @@ -81,7 +81,7 @@ function configure (env, ctx) {
const opCtx = {app, ctx, env, req, res};
opCtx.auth = await security.authenticate(opCtx);
await security.demandPermission(opCtx, 'api:entries:read');
res.status(200).end();
res.status(apiConst.HTTP.OK).end();
} catch (error) {
console.error(error);
}
Expand Down