Skip to content

Commit 8a815b2

Browse files
authored
Merge pull request #575 from watson-developer-cloud/add-global-transaction-id
add global transaction id to error body
2 parents 09cbf02 + 4d775e3 commit 8a815b2

File tree

3 files changed

+27
-50
lines changed

3 files changed

+27
-50
lines changed

lib/requestwrapper.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { PassThrough as readableStream } from 'stream';
2626

2727
const pkg = require('../package.json');
2828
const isBrowser = typeof window === 'object';
29+
const globalTransactionId = 'x-global-transaction-id';
2930

3031
/**
3132
* @private
@@ -61,6 +62,9 @@ export function formatErrorIfExists(cb: Function): request.RequestCallback {
6162
error = new Error(error.message || error.error || error);
6263
error.body = body;
6364
}
65+
if (response && response.headers) {
66+
error[globalTransactionId] = response.headers[globalTransactionId];
67+
}
6468
cb(error, body, response);
6569
return;
6670
}
@@ -74,13 +78,14 @@ export function formatErrorIfExists(cb: Function): request.RequestCallback {
7478

7579
// for api-key services
7680
if (response.statusMessage === 'invalid-api-key') {
77-
cb(
78-
{
79-
error: response.statusMessage,
80-
code: response.statusMessage === 'invalid-api-key' ? 401 : 400
81-
},
82-
null
83-
);
81+
const error = {
82+
error: response.statusMessage,
83+
code: response.statusMessage === 'invalid-api-key' ? 401 : 400
84+
};
85+
if (response.headers) {
86+
error[globalTransactionId] = response.headers[globalTransactionId];
87+
}
88+
cb(error, null);
8489
return;
8590
}
8691

@@ -125,6 +130,9 @@ export function formatErrorIfExists(cb: Function): request.RequestCallback {
125130
}
126131
body = null;
127132
}
133+
if (error && response && response.headers) {
134+
error[globalTransactionId] = response.headers[globalTransactionId];
135+
}
128136
cb(error, body, response);
129137
return;
130138
};

test/integration/test.tone_analyzer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const fs = require('fs');
44
const nock = require('nock');
5+
const assert = require('assert');
56
const watson = require('../../index');
67
const path = require('path');
78
const authHelper = require('./auth_helper.js');
@@ -31,6 +32,17 @@ describe('tone_analyzer_integration', function() {
3132
tone_analyzer.tone({ tone_input: mobydick, content_type: 'text/plain' }, done);
3233
});
3334

35+
it('failing tone()', function(done) {
36+
// this is a failing test
37+
const mobydick = fs.readFileSync(path.join(__dirname, '../resources/mobydick.txt'), 'utf8');
38+
tone_analyzer.tone({ tone_input: mobydick, content_type: 'invalid content type' }, (err, res) => {
39+
assert(err);
40+
assert(err['x-global-transaction-id']);
41+
assert(typeof err['x-global-transaction-id'] === 'string');
42+
});
43+
done();
44+
});
45+
3446
it('toneChat()', function(done) {
3547
const utterances = {
3648
utterances: [

test/integration/test.visual_recognition.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -140,47 +140,4 @@ describe('visual_recognition_integration', function() {
140140
});
141141
});
142142
});
143-
144-
// this endpoint is flakey
145-
// describe.skip('recognizeText()', function() {
146-
// it('read text in an uploaded image', function(done) {
147-
// const params = {
148-
// images_file: fs.createReadStream(__dirname + '/../resources/car.png')
149-
// };
150-
// visual_recognition.recognizeText(params, function(err, result) {
151-
// if (err) {
152-
// return done(err);
153-
// }
154-
155-
// // console.log(JSON.stringify(actual, null, 2));
156-
157-
// assert.equal(result.images_processed, 1);
158-
// assert.equal(result.images[0].image, 'car.png');
159-
// assert(result.images[0].text);
160-
// assert(result.images[0].words.length);
161-
162-
// done();
163-
// });
164-
// });
165-
166-
// it('read text an image via url', function(done) {
167-
// const params = {
168-
// url: 'https://watson-test-resources.mybluemix.net/resources/car.png'
169-
// };
170-
// visual_recognition.recognizeText(params, function(err, result) {
171-
// if (err) {
172-
// return done(err);
173-
// }
174-
// // console.log(JSON.stringify(result, null, 2));
175-
176-
// assert.equal(result.images_processed, 1);
177-
// assert.equal(result.images[0].resolved_url, 'https://watson-test-resources.mybluemix.net/resources/car.png');
178-
// assert.equal(result.images[0].source_url, 'https://watson-test-resources.mybluemix.net/resources/car.png');
179-
// assert(result.images[0].text);
180-
// assert(result.images[0].words.length);
181-
182-
// done();
183-
// });
184-
// });
185-
// });
186143
}); // vr

0 commit comments

Comments
 (0)