Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error handler in updating an array #223

Merged
merged 1 commit into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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