Skip to content

Commit

Permalink
fix: error handler in updating an array (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-lobanov authored Oct 13, 2020
1 parent 50d4841 commit 96e2e80
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
5 changes: 2 additions & 3 deletions build/airtable.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,13 +885,12 @@ var Table = /** @class */ (function () {
done = optsOrDone || recordDataOrOptsOrDone;
var method = isDestructiveUpdate ? 'put' : 'patch';
var requestData = assign_1.default({ records: recordsData }, opts);
this._base.runAction(method, "/" + this._urlEncodedNameOrId() + "/", {}, requestData, function (err, resp, _a) {
var records = _a.records;
this._base.runAction(method, "/" + this._urlEncodedNameOrId() + "/", {}, requestData, function (err, resp, body) {
if (err) {
done(err);
return;
}
var result = records.map(function (record) {
var result = body.records.map(function (record) {
return new record_1.default(_this, record.id, record);
});
done(null, result);
Expand Down
4 changes: 2 additions & 2 deletions src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ class Table {
`/${this._urlEncodedNameOrId()}/`,
{},
requestData,
(err, resp, {records}) => {
(err, resp, body) => {
if (err) {
done(err);
return;
}

const result = records.map(record => {
const result = body.records.map(record => {
return new Record(this, record.id, record);
});
done(null, result);
Expand Down
30 changes: 30 additions & 0 deletions test/update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,36 @@ describe('record updates', function() {
}
);
});

it('can throw an error if a multi-record update call fails due to network error', function(done) {
testExpressApp.set('handler override', function(req, res) {
res.status(522).end();
});

return airtable
.base('app123')
.table('Table')
.update([
{
id: 'rec123',
fields: {foo: 'boo'},
},
{
id: 'rec456',
fields: {bar: 'yar'},
},
])
.then(
function() {
throw new Error('Promise unexpectly fufilled.');
},
function(err) {
expect(err.statusCode).toBe(522);
expect(err.message).toBe('An unexpected error occurred');
done();
}
);
});
});

describe('destructive updates', function() {
Expand Down

0 comments on commit 96e2e80

Please sign in to comment.