-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy patherror-utils.js
More file actions
41 lines (31 loc) · 847 Bytes
/
error-utils.js
File metadata and controls
41 lines (31 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
module.exports = function (errors) {
var jsonapi = {
errors: []
};
errors.forEach(function (error) {
var opts = {};
if (error.id) { opts.id = error.id; }
if (error.status) { opts.status = error.status; }
if (error.code) { opts.code = error.code; }
if (error.title) { opts.title = error.title; }
if (error.detail) { opts.detail = error.detail; }
if (error.source) {
opts.source = {};
if (error.source.pointer) {
opts.source.pointer = error.source.pointer;
}
if (error.source.parameter) {
opts.source.parameter = error.source.parameter;
}
}
if (error.links) {
opts.links = { about: error.links.about };
}
if (error.meta) {
opts.meta = error.meta;
}
jsonapi.errors.push(opts);
});
return jsonapi;
};