Merge pull request #33490 from overleaf/em-parse-req-errors-2

Reintroduce custom error types in request validation

GitOrigin-RevId: 1985ca04c8fe693fb836b042517d94700343bc46
This commit is contained in:
Eric Mc Sween
2026-05-08 08:10:13 +00:00
committed by Copybot
parent 8c0589df7f
commit 2bb35fafb8
17 changed files with 105 additions and 85 deletions
@@ -176,31 +176,12 @@ describe('Authentication', function () {
}
})
it('should return 400 with bad email (missing @)', async function () {
const { statusCode, body } = await tryLoginWithEmail('foo')
const { statusCode } = await tryLoginWithEmail('foo')
expect(statusCode).to.equal(400)
expect(body).to.deep.equal({
name: 'ZodValidationError',
details: [
{ code: 'custom', path: [], message: 'Invalid email address' },
],
statusCode: 400,
})
})
it('should return 400 with bad email (number)', async function () {
const { statusCode, body } = await tryLoginWithEmail(1)
const { statusCode } = await tryLoginWithEmail(1)
expect(statusCode).to.equal(400)
expect(body).to.deep.equal({
name: 'ZodValidationError',
details: [
{
expected: 'string',
code: 'invalid_type',
path: [],
message: 'Invalid input: expected string, received number',
},
],
statusCode: 400,
})
})
})
})
@@ -219,14 +219,13 @@ describe('Project CRUD', function () {
})
it('returns a 400 when publicAccessLevel is an unsupported access level', async function () {
await this.user.makePrivate(this.projectId)
const { response, body } = await this.user.doRequest('POST', {
const { response } = await this.user.doRequest('POST', {
url: `/project/${this.projectId}/settings/admin`,
json: {
publicAccessLevel: 'readOnly',
},
})
expect(response.statusCode).to.equal(400)
expect(body.details[0].message).to.equal('unexpected access level')
const project = await Project.findById(this.projectId).exec()
expect(project.publicAccesLevel).to.equal('private')
})
@@ -375,11 +375,6 @@ describe('ProjectInviteTests', function () {
return done(err)
}
expect(response.statusCode).to.equal(400)
expect(body.details).to.have.lengthOf(1)
expect(response.body.details[0].path).to.eql(['body', 'email'])
expect(response.body.details[0].message).to.equal(
'Invalid input: expected string, received object'
)
done()
}
)
@@ -404,14 +399,6 @@ describe('ProjectInviteTests', function () {
return done(err)
}
expect(response.statusCode).to.equal(400)
expect(body.details).to.have.lengthOf(1)
expect(response.body.details[0].path).to.eql([
'body',
'privileges',
])
expect(response.body.details[0].message).to.equal(
'Invalid option: expected one of "readOnly"|"readAndWrite"|"review"'
)
done()
}
)