API Docs for: 0.8.0
Show:

File: include/error/pb_error.js

  1. /*
  2. Copyright (C) 2016 PencilBlue, LLC
  3.  
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. 'use strict';
  18.  
  19. //dependencies
  20. var util = require('../util.js');
  21.  
  22. module.exports = function PBErrorModule(pb) {
  23.  
  24. /**
  25. * Specialized application error that knows what status code to return
  26. *
  27. * @module ErrorSuccess
  28. * @class PBError
  29. * @constructor
  30. * @main ErrorSuccess
  31. * @param {String} message The error message
  32. * @param {Number} httpStatus The header code for the error
  33. */
  34. function PBError(message, httpStatus) {
  35. this.message = message ? message : '';
  36. this.httpStatus = httpStatus ? httpStatus : 500;
  37. this.localizationKey = null;
  38. this.source = null;
  39. }
  40.  
  41. //setup inheritance
  42. util.inherits(PBError, Error);
  43.  
  44. /**
  45. * Sets the localization key for the error
  46. *
  47. * @method setLocalizationKey
  48. * @param {String} key The localization key
  49. * @return {object} The PBError object
  50. */
  51. PBError.prototype.setLocalizatonKey = function(key){
  52. this.localizationKey = key;
  53. return this;
  54. };
  55.  
  56. /**
  57. * Sets the source for the error
  58. *
  59. * @method setSource
  60. * @param {Object} err The error source
  61. * @return {object} The PBError object
  62. */
  63. PBError.prototype.setSource = function(err){
  64. this.source = err;
  65. return this;
  66. };
  67.  
  68. return PBError;
  69. };
  70.