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

Minor: wrap the inner error on retried transactions and return when deadline exceeded #309

Merged
merged 18 commits into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from 7 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
17 changes: 13 additions & 4 deletions src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'use strict';

const {promisifyAll} = require('@google-cloud/promisify');
const common = require('@google-cloud/common-grpc');
const extend = require('extend');
const gax = require('google-gax');
const is = require('is');
Expand All @@ -40,6 +41,11 @@ const TransactionRequest = require('./transaction-request');
*/
const UNKNOWN = 2;

/**
* the gRPC `DEADLINE_EXCEEDED` error code.
*/
const DEADLINE_EXCEEDED = 4;

/**
* The gRPC `ABORTED` error code.
*
Expand Down Expand Up @@ -720,10 +726,13 @@ class Transaction extends TransactionRequest {
* @return {object}
*/
static createDeadlineError_(err) {
return extend({}, err, {
code: 4,
message: 'Deadline for Transaction exceeded.',
});
let apiError = new common.util.ApiError(

This comment was marked as spam.

'Deadline for Transaction exceeded.'
);
apiError.code = DEADLINE_EXCEEDED;
apiError.errors = [err];

return apiError;
}
/**
* Extracts retry delay and formats into milliseconds.
Expand Down
14 changes: 6 additions & 8 deletions test/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,14 @@ describe('Transaction', function() {
b: 'b',
};

const expectedError = {
code: 4,
message: 'Deadline for Transaction exceeded.',
a: 'a',
b: 'b',
};

const formattedError = Transaction.createDeadlineError_(originalError);

assert.deepStrictEqual(expectedError, formattedError);
assert.strictEqual(formattedError.code, 4);

This comment was marked as spam.

This comment was marked as spam.

assert.strictEqual(
formattedError.message,
'Deadline for Transaction exceeded.'
);
assert.deepStrictEqual(originalError, formattedError.errors[0]);
assert.notStrictEqual(originalError, formattedError);
});
});
Expand Down