Browse Source

Merge pull request #1274 from LancerComet/response-format-1266

Uniform 400 response format of REST /auth/signin
pull/1277/head
navi 3 years ago committed by GitHub
parent
commit
2c2da50dc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      packages/nocodb/src/__tests__/rest.test.ts
  2. 24
      packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts

7
packages/nocodb/src/__tests__/rest.test.ts

@ -190,6 +190,13 @@ describe('{Auth, CRUD, HasMany, Belongs} Tests', () => {
.expect(400, done);
});
it('Signup with no credentials', done => {
request(app)
.post('/auth/signin')
.send({})
.expect(400, done)
})
it('Forgot password with a non-existing email id', function(done) {
request(app)
.post('/auth/password/forgot')

24
packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts

@ -635,7 +635,13 @@ export default class RestAuthCtrl {
try {
if (!user || !user.email) {
if (err) {
return res.status(400).send(err);
// This exception was thrown directly before.
// In order to avoid breaking change, both "msg" and "message" are returned.
const message = err.message ?? ''
return res.status(400).send({
msg: message,
message
});
}
if (info) {
return res.status(400).send(info);
@ -694,7 +700,13 @@ export default class RestAuthCtrl {
try {
if (!user || !user.email) {
if (err) {
return res.status(400).send(err);
// This exception was thrown directly before.
// In order to avoid breaking change, both "msg" and "message" are returned.
const message = err.message ?? ''
return res.status(400).send({
msg: message,
message
});
}
if (info) {
return res.status(400).send(info);
@ -753,7 +765,13 @@ export default class RestAuthCtrl {
try {
if (!user || !user.email) {
if (err) {
return res.status(400).send(err);
// This exception was thrown directly before.
// In order to avoid breaking change, both "msg" and "message" are returned.
const message = err.message ?? ''
return res.status(400).send({
msg: message,
message
});
}
if (info) {
return res.status(400).send(info);

Loading…
Cancel
Save