Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding special error parsing

  • Loading branch information...
commit 11dbdee6005ba3c359025e70b7276a3c6ffd428c 1 parent 6319b80
@andrerod andrerod authored
View
30 lib/services/core/serviceclient.js
@@ -492,7 +492,35 @@ ServiceClient.prototype._parseResponse = function (response) {
if (parser.resultObject) {
parsedBody = parser.resultObject;
} else {
- parsedBody = { parsingError: parseError };
+ // If it failed to parse, try to parse in string format
+ if (response.body) {
+ response.body = response.body.toLowerCase();
+
+ var codeIndex = response.body.indexOf('code:');
+ if (codeIndex !== -1) {
+ var resultObject = { };
+
+ var endIndex = response.body.indexOf(':', codeIndex);
+ if (endIndex === -1) {
+ endIndex = response.body.length - 1;
+ }
+
+ var codeMessage = response.body.substr(codeIndex + 5, endIndex - codeIndex - 1);
+ resultObject['code'] = codeMessage;
+
+ var detailIndex = response.body.indexOf('detail:');
+ if (detailIndex !== -1) {
+ var detailMessage = response.body.substr(detailIndex + 7);
+ resultObject['detail'] = detailMessage;
+ }
+
+ parsedBody = resultObject;
+ }
+ }
+
+ if (!parsedBody) {
+ parsedBody = { parsingError: parseError };
+ }
}
}
View
6 test/services/serviceBus/servicebusservice-tests.js
@@ -1672,21 +1672,23 @@ suite('servicebusservice-tests', function () {
done();
});
- test('invalidNamespaceGivesError', function (done) {
+ test('invalidAccessKeyGivesError', function (done) {
var serviceBusService = azure.createServiceBusService(process.env['AZURE_SERVICEBUS_NAMESPACE'], 'key');
// fails, with an error on the callback.
serviceBusService.createTopicIfNotExists('Topic', function(error) {
assert.notEqual(error, null);
+ assert.equal(error.code, '401');
done();
});
});
- test('invalidKeyGivesError', function (done) {
+ test('invalidNamespaceGivesError', function (done) {
var serviceBusService = azure.createServiceBusService('BoGuS', process.env['AZURE_SERVICEBUS_ACCESS_KEY']);
// fails, with an error on the callback.
serviceBusService.createTopicIfNotExists('Topic', function(error) {
assert.notEqual(error, null);
+ assert.equal(error.code, 'ENOTFOUND');
done();
});
Please sign in to comment.
Something went wrong with that request. Please try again.