Skip to content

Commit

Permalink
Attach sent record data to batch error objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Jul 6, 2015
1 parent fe8eae5 commit 45a5f8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export default class Api {
err[key] = res[key];
return err;
}, new Error("BATCH request failed: " + res.message));
res.responses.forEach(response => {
res.responses.forEach((response, index) => {
// TODO: handle 409 when unicity rule is violated (ex. POST with
// existing id, unique field, etc.)
if (response.status && response.status >= 200 && response.status < 400) {
Expand All @@ -187,9 +187,8 @@ export default class Api {
});
} else {
results.errors.push({
// TODO: since responses come in the same order, there should be a
// way to get original record id
path: response.path, // this is the only way to have the id…
path: response.path,
sent: records[index],
error: response.body
});
}
Expand Down
5 changes: 2 additions & 3 deletions test/api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,8 @@ describe("Api", () => {
errors: [
{
path: "/v0/buckets/blog/collections/articles/records/1",
error: {
500: true
}
sent: published[0],
error: { 500: true }
}
],
published: []
Expand Down

0 comments on commit 45a5f8e

Please sign in to comment.