Skip to content

Commit

Permalink
Use constants instead of number literals for http status codes (#5276)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobsandberg authored and sulkaharo committed Dec 14, 2019
1 parent 0ea36ab commit de70aa2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
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

0 comments on commit de70aa2

Please sign in to comment.