mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
add res.respond, fix linting
This commit is contained in:
@@ -5,6 +5,7 @@ describe('notFound Middleware', () => {
|
||||
let request = requester().get('/api/v3/dummy-url');
|
||||
|
||||
return expect(request).to.eventually.be.rejected.and.eql({
|
||||
success: false,
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: 'Not found.',
|
||||
|
||||
@@ -39,6 +39,7 @@ describe('POST /user/auth/local/register', () => {
|
||||
password,
|
||||
confirmPassword: confirmPassword,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
success: false,
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
message: t('invalidReqParams'),
|
||||
@@ -56,6 +57,7 @@ describe('POST /user/auth/local/register', () => {
|
||||
password,
|
||||
confirmPassword,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
success: false,
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
message: t('invalidReqParams'),
|
||||
@@ -72,6 +74,7 @@ describe('POST /user/auth/local/register', () => {
|
||||
password,
|
||||
confirmPassword: password,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
success: false,
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
message: t('invalidReqParams'),
|
||||
@@ -90,6 +93,7 @@ describe('POST /user/auth/local/register', () => {
|
||||
password,
|
||||
confirmPassword: password,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
success: false,
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
message: t('invalidReqParams'),
|
||||
@@ -107,6 +111,7 @@ describe('POST /user/auth/local/register', () => {
|
||||
email: email,
|
||||
confirmPassword: confirmPassword,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
success: false,
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
message: t('invalidReqParams'),
|
||||
@@ -138,6 +143,7 @@ describe('POST /user/auth/local/register', () => {
|
||||
password: password,
|
||||
confirmPassword: password,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
success: false,
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('usernameTaken'),
|
||||
@@ -155,6 +161,7 @@ describe('POST /user/auth/local/register', () => {
|
||||
password,
|
||||
confirmPassword: password,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
success: false,
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('emailTaken'),
|
||||
|
||||
@@ -252,6 +252,7 @@ function _requestMaker (user, method, additionalSets) {
|
||||
|
||||
if (API_V === 'v3') {
|
||||
return reject({
|
||||
success: err.response.body.success,
|
||||
code: err.status,
|
||||
error: err.response.body.error,
|
||||
message: err.response.body.message,
|
||||
|
||||
@@ -48,6 +48,7 @@ api.registerLocal = {
|
||||
if (validationErrors) return next(validationErrors);
|
||||
|
||||
let { email, username, password } = req.body;
|
||||
|
||||
// Get the lowercase version of username to check that we do not have duplicates
|
||||
// So we can search for it in the database and then reject the choosen username if 1 or more results are found
|
||||
email = email.toLowerCase();
|
||||
|
||||
@@ -34,7 +34,7 @@ export function authWithHeaders (optional = false) {
|
||||
next();
|
||||
})
|
||||
.catch(next);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Authenticate a request through a valid session
|
||||
|
||||
@@ -68,7 +68,5 @@ export default function errorHandler (err, req, res, next) {
|
||||
|
||||
if (responseErr.errors) jsonRes.errors = responseErr.errors;
|
||||
|
||||
return res
|
||||
.status(responseErr.httpCode)
|
||||
.json(jsonRes);
|
||||
return res.respond(responseErr.httpCode, jsonRes);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import routes from '../../libs/api-v3/setupRoutes';
|
||||
import notFoundHandler from './notFound';
|
||||
import nconf from 'nconf';
|
||||
import morgan from 'morgan';
|
||||
import responseHandler from './response';
|
||||
|
||||
const IS_PROD = nconf.get('IS_PROD');
|
||||
const DISABLE_LOGGING = nconf.get('DISABLE_REQUEST_LOGGING');
|
||||
@@ -22,6 +23,7 @@ export default function attachMiddlewares (app) {
|
||||
app.use(bodyParser.json());
|
||||
app.use(expressValidator()); // TODO config
|
||||
app.use(analytics);
|
||||
app.use(responseHandler);
|
||||
app.use(getUserLanguage);
|
||||
|
||||
app.use('/api/v3', routes);
|
||||
|
||||
Reference in New Issue
Block a user