errors.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. let Errors = {
  2. unknown: 'An unknown error occured on our end. Please try again later',
  3. accountAlreadyCreated: 'This account has already been created',
  4. missingParameter (param) {
  5. return `The request is missing the parameter "${param}"`
  6. },
  7. invalidParameterType (param, type) {
  8. return `Parameter "${param}" must be of type ${type}`
  9. },
  10. parameterLengthTooSmall (param, length) {
  11. return `Parameter "${param}" must be greater than ${length} characters in length`
  12. },
  13. parameterLengthTooLarge (param, length) {
  14. return `Parameter "${param}" must be less than ${length} characters in length`
  15. }
  16. }
  17. let ProcessedErrors = {}
  18. function processErrors(errorName) {
  19. let temp
  20. if(typeof Errors[errorName] === 'function') {
  21. temp = function() {
  22. let message = Errors[errorName](...arguments)
  23. return {
  24. name: errorName,
  25. message: message
  26. }
  27. }
  28. } else {
  29. temp = {}
  30. temp.name = errorName
  31. temp.message = Errors[errorName]
  32. }
  33. return temp
  34. }
  35. for(var errorName in Errors) {
  36. ProcessedErrors[errorName] = processErrors(errorName)
  37. }
  38. ProcessedErrors.VALIDATION_ERROR = 'VALIDATION_ERROR';
  39. module.exports = ProcessedErrors