mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
feat(server): introduce user friendly server errors (#7111)
This commit is contained in:
@@ -119,7 +119,7 @@ test('should not be able to sign in if email is invalid', async t => {
|
||||
.send({ email: '' })
|
||||
.expect(400);
|
||||
|
||||
t.is(res.body.message, 'Invalid email address');
|
||||
t.is(res.body.message, 'An invalid email provided.');
|
||||
});
|
||||
|
||||
test('should not be able to sign in if forbidden', async t => {
|
||||
@@ -130,7 +130,7 @@ test('should not be able to sign in if forbidden', async t => {
|
||||
await request(app.getHttpServer())
|
||||
.post('/api/auth/sign-in')
|
||||
.send({ email: u1.email })
|
||||
.expect(HttpStatus.BAD_REQUEST);
|
||||
.expect(HttpStatus.FORBIDDEN);
|
||||
|
||||
t.true(mailer.sendSignInMail.notCalled);
|
||||
|
||||
|
||||
@@ -86,9 +86,11 @@ test('should not be able to visit private api if not signed in', async t => {
|
||||
.get('/private')
|
||||
.expect(HttpStatus.UNAUTHORIZED)
|
||||
.expect({
|
||||
statusCode: 401,
|
||||
message: 'You are not signed in.',
|
||||
error: 'Unauthorized',
|
||||
status: 401,
|
||||
code: 'Unauthorized',
|
||||
type: 'AUTHENTICATION_REQUIRED',
|
||||
name: 'AUTHENTICATION_REQUIRED',
|
||||
message: 'You must sign in first to access this resource.',
|
||||
});
|
||||
|
||||
t.assert(true);
|
||||
|
||||
@@ -66,7 +66,7 @@ test('should throw if email duplicated', async t => {
|
||||
const { auth } = t.context;
|
||||
|
||||
await t.throwsAsync(() => auth.signUp('u1', 'u1@affine.pro', '1'), {
|
||||
message: 'Email was taken',
|
||||
message: 'This email has already been registered.',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -82,7 +82,7 @@ test('should throw if user not found', async t => {
|
||||
const { auth } = t.context;
|
||||
|
||||
await t.throwsAsync(() => auth.signIn('u2@affine.pro', '1'), {
|
||||
message: 'Invalid sign in credentials',
|
||||
message: 'Wrong user email or password.',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -95,7 +95,8 @@ test('should throw if password not set', async t => {
|
||||
});
|
||||
|
||||
await t.throwsAsync(() => auth.signIn('u2@affine.pro', '1'), {
|
||||
message: 'User Password is not set. Should login through email link.',
|
||||
message:
|
||||
'You are trying to sign in by a different method than you signed up with.',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -103,7 +104,7 @@ test('should throw if password not match', async t => {
|
||||
const { auth } = t.context;
|
||||
|
||||
await t.throwsAsync(() => auth.signIn('u1@affine.pro', '2'), {
|
||||
message: 'Invalid sign in credentials',
|
||||
message: 'Wrong user email or password.',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -118,7 +119,7 @@ test('should be able to change password', async t => {
|
||||
await t.throwsAsync(
|
||||
() => auth.signIn('u1@affine.pro', '1' /* old password */),
|
||||
{
|
||||
message: 'Invalid sign in credentials',
|
||||
message: 'Wrong user email or password.',
|
||||
}
|
||||
);
|
||||
|
||||
@@ -135,7 +136,7 @@ test('should be able to change email', async t => {
|
||||
await auth.changeEmail(u1.id, 'u2@affine.pro');
|
||||
|
||||
await t.throwsAsync(() => auth.signIn('u1@affine.pro' /* old email */, '1'), {
|
||||
message: 'Invalid sign in credentials',
|
||||
message: 'Wrong user email or password.',
|
||||
});
|
||||
|
||||
signedInU1 = await auth.signIn('u2@affine.pro', '1');
|
||||
|
||||
Reference in New Issue
Block a user