Wrapped additional error data under data

This commit is contained in:
Jori Lallo
2018-03-07 00:00:58 -08:00
parent f5c1ddf8b9
commit 983b8fe9a0
5 changed files with 8 additions and 6 deletions

View File

@ -45,9 +45,9 @@ class AuthStore {
this.team = res.data.team;
});
} catch (err) {
if (err.data.error === 'user_suspended') {
if (err.error.error === 'user_suspended') {
this.isSuspended = true;
this.suspendedContactEmail = err.data.adminEmail;
this.suspendedContactEmail = err.error.data.adminEmail;
}
}
};

View File

@ -84,7 +84,7 @@ class ApiClient {
})
.catch(error => {
error.response.json().then(json => {
error.data = json;
error.error = json;
reject(error);
});
});

View File

@ -55,7 +55,7 @@ api.use(async (ctx, next) => {
error: _.snakeCase(err.id || error),
status: err.status,
message,
adminEmail: err.adminEmail ? err.adminEmail : undefined,
data: err.errorData ? err.errorData : undefined,
};
}
});

View File

@ -181,7 +181,7 @@ describe('Authentication middleware', async () => {
expect(e.message).toEqual(
'Your access has been suspended by the team admin'
);
expect(e.adminEmail).toEqual(admin.email);
expect(e.errorData.adminEmail).toEqual(admin.email);
}
});
});

View File

@ -22,7 +22,9 @@ export function AdminRequiredError(
export function UserSuspendedError({ adminEmail }: { adminEmail: string }) {
return httpErrors(403, 'Your access has been suspended by the team admin', {
id: 'user_suspended',
adminEmail,
errorData: {
adminEmail,
},
});
}