Skip to content

Commit ba4ead7

Browse files
committed
Ensure error objects have consistent property names
`message` is used as a high-level description of the errors `detail` is optional and has an plain language explanation of the individual errors `errors` is an array of each individual problem from `detail` in a machine-readable format
1 parent 64e39aa commit ba4ead7

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

server/controllers/project.controller/__test__/createProject.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ describe('project.controller', () => {
244244
expect(response.json).toHaveBeenCalled();
245245

246246
expect(JSON.parse(JSON.stringify(doc))).toMatchObject({
247-
message: 'Slug "a-slug" is not unique. Check cde123'
247+
message: 'Sketch Validation Failed',
248+
detail: 'Slug "a-slug" is not unique. Check cde123'
248249
});
249250

250251
done();
@@ -275,7 +276,8 @@ describe('project.controller', () => {
275276
const responseBody = JSON.parse(JSON.stringify(doc));
276277

277278
expect(response.status).toHaveBeenCalledWith(422);
278-
expect(responseBody.name).toBe('File Validation Failed');
279+
expect(responseBody.message).toBe('File Validation Failed');
280+
expect(responseBody.detail).not.toBeNull();
279281
expect(responseBody.errors.length).toBe(1);
280282
expect(responseBody.errors).toEqual([
281283
{ name: 'index.html', message: 'missing \'url\' or \'content\'' }
@@ -305,8 +307,8 @@ describe('project.controller', () => {
305307
const responseBody = JSON.parse(JSON.stringify(doc));
306308

307309
expect(response.status).toHaveBeenCalledWith(422);
308-
expect(responseBody.name).toBe('File Validation Failed');
309-
expect(responseBody.message).toBe('\'files\' must be an object');
310+
expect(responseBody.message).toBe('File Validation Failed');
311+
expect(responseBody.detail).toBe('\'files\' must be an object');
310312

311313
done();
312314
}

server/controllers/project.controller/__test__/deleteProject.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ describe('project.controller', () => {
4646

4747
function expectations() {
4848
expect(response.status).toHaveBeenCalledWith(403);
49-
expect(response.json).toHaveBeenCalledWith({ success: false, message: 'Authenticated user does not match owner of project' });
49+
expect(response.json).toHaveBeenCalledWith({
50+
message: 'Authenticated user does not match owner of project'
51+
});
5052

5153
done();
5254
}
@@ -73,7 +75,9 @@ describe('project.controller', () => {
7375

7476
function expectations() {
7577
expect(response.status).toHaveBeenCalledWith(404);
76-
expect(response.json).toHaveBeenCalledWith({ success: false, message: 'Project with that id does not exist' });
78+
expect(response.json).toHaveBeenCalledWith({
79+
message: 'Project with that id does not exist'
80+
});
7781

7882
done();
7983
}
@@ -103,7 +107,7 @@ describe('project.controller', () => {
103107

104108
function expectations() {
105109
expect(response.status).toHaveBeenCalledWith(200);
106-
expect(response.json).toHaveBeenCalledWith({ success: true });
110+
expect(response.json).not.toHaveBeenCalled();
107111
expect(deleteObjectsFromS3).toHaveBeenCalled();
108112

109113
done();

server/controllers/project.controller/createProject.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ export function apiCreateProject(req, res) {
3838

3939
function sendValidationErrors(err, type, code = 422) {
4040
res.status(code).json({
41-
name: `${type} Validation Failed`,
42-
message: err.message,
41+
message: `${type} Validation Failed`,
42+
detail: err.message,
4343
errors: err.files,
4444
});
4545
}
4646

4747
// TODO: Error handling to match spec
4848
function sendFailure(err) {
49-
res.status(500).json({ success: false });
49+
res.status(500).end();
5050
}
5151

5252
function handleErrors(err) {

server/controllers/project.controller/deleteProject.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function deleteFilesFromS3(files) {
2121

2222
export default function deleteProject(req, res) {
2323
function sendFailure(error) {
24-
res.status(error.code).json({ success: false, message: error.message });
24+
res.status(error.code).json({ message: error.message });
2525
}
2626

2727
function sendProjectNotFound() {
@@ -47,7 +47,7 @@ export default function deleteProject(req, res) {
4747
return;
4848
}
4949

50-
res.status(200).json({ success: true });
50+
res.status(200).end();
5151
});
5252
}
5353

0 commit comments

Comments
 (0)