Improve check jobs parameters tests

This commit is contained in:
Chocobozzz 2017-12-28 14:40:11 +01:00
parent eec63bbc0f
commit 93e4a311f3
No known key found for this signature in database
GPG key ID: 583A612D890159BE
3 changed files with 30 additions and 40 deletions

View file

@ -1,10 +1,10 @@
import 'express-validator'
import * as express from 'express'
import * as OAuthServer from 'express-oauth-server'
import { logger } from '../helpers/logger'
import 'express-validator'
import { OAUTH_LIFETIME } from '../initializers'
const oAuthServer = new OAuthServer({
useErrorHandler: true,
accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN,
refreshTokenLifetime: OAUTH_LIFETIME.REFRESH_TOKEN,
model: require('../lib/oauth-model')
@ -13,14 +13,12 @@ const oAuthServer = new OAuthServer({
function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) {
oAuthServer.authenticate()(req, res, err => {
if (err) {
logger.error('Cannot authenticate.', err)
return res.sendStatus(500)
}
if (res.statusCode === 401 || res.statusCode === 400 || res.statusCode === 503) {
return res.json({
error: 'Authentication failed.'
}).end()
return res.status(err.status)
.json({
error: 'Authentication failed.',
code: err.name
})
.end()
}
return next()