- 1 :
- 2 :
(function(root, factory) {
- 3 :
- 4 :
if (typeof module === 'object' && module.exports) {
- 5 :
// CommonJS-like environments that support module.exports, like Node.
- 6 :
module.exports = factory(require('./CommonUtil'), require('./wrappers/ErrorResponse'));
- 7 :
}
- 8 :
}(this, function(CommonUtil, ErrorResponse) {
- 9 :
'use strict';
- 10 :
- 11 :
var exports = function (message) {
- 12 :
var _this = this;
- 13 :
- 14 :
Error.call(_this);
- 15 :
this.stack = (new Error()).stack;
- 16 :
- 17 :
_this['message'] = '' + message;
- 18 :
_this['error_response'] = [];
- 19 :
};
- 20 :
- 21 :
exports.prototype = Object.create(Error.prototype);
- 22 :
- 23 :
exports.prototype.constructor = exports;
- 24 :
- 25 :
exports.constructFromHttpResponse = function (httpErrorMessage, response, obj) {
- 26 :
obj = obj || new exports(httpErrorMessage);
- 27 :
if (response) {
- 28 :
if (response.hasOwnProperty('status')) {
- 29 :
obj['http_status_code'] = response['status'];
- 30 :
}
- 31 :
- 32 :
if (response.hasOwnProperty('text')) {
- 33 :
obj['response_body'] = response['text'];
- 34 :
if (response['text'] && CommonUtil.isJsonString(response['text'])) {
- 35 :
var errorResponse = CommonUtil.parseJSON(response['text']);
- 36 :
if (errorResponse && errorResponse.hasOwnProperty('errors') && Array.isArray(errorResponse['errors'])) {
- 37 :
obj['error_response'] = ErrorResponse.constructFromObject(errorResponse);
- 38 :
}
- 39 :
}
- 40 :
}
- 41 :
- 42 :
if (response.hasOwnProperty('header')) {
- 43 :
obj['http_response_headers'] = response['header'];
- 44 :
}
- 45 :
}
- 46 :
return obj;
- 47 :
};
- 48 :
- 49 :
exports.getDefaultException = function (error) {
- 50 :
var exception = new exports(error.message);
- 51 :
exception['stack'] = error.stack;
- 52 :
return exception;
- 53 :
};
- 54 :
- 55 :
/**
- 56 :
* @member {String} http_status_code
- 57 :
*/
- 58 :
exports.prototype['http_status_code'] = undefined;
- 59 :
/**
- 60 :
* @member {wrappers/ErrorResponse} error_response
- 61 :
*/
- 62 :
exports.prototype['error_response'] = undefined;
- 63 :
/**
- 64 :
* @member {wrappers/InvocationContext} invocation_context
- 65 :
*/
- 66 :
exports.prototype['invocation_context'] = undefined;
- 67 :
/**
- 68 :
* @member {Boolean} is_timed_out
- 69 :
*/
- 70 :
exports.prototype['is_timed_out'] = undefined;
- 71 :
- 72 :
return exports;
- 73 :
- 74 :
}));