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