|
@@ -1,35 +1,35 @@
|
|
|
let Errors = {
|
|
|
- unknown: 'An unknown error occured on our end. Please try again later',
|
|
|
- accountAlreadyCreated: 'This account has already been created',
|
|
|
- categoryAlreadyExists: 'This category has already been created',
|
|
|
- accountDoesNotExist: 'This account does not exist',
|
|
|
- invalidCategory: 'This category does not exist',
|
|
|
- invalidLoginCredentials: 'Invalid login credentials were provided',
|
|
|
- requestNotAuthorized: 'The request was not authorized',
|
|
|
- invalidToken: 'The token provided was not valid',
|
|
|
- noSettings: 'You haven\'t added any settings yet',
|
|
|
- passwordSame: 'You can\'t set it to the same password',
|
|
|
- cannotLikeOwnPost: 'You can\'t like your own post',
|
|
|
- threadLocked: 'You can\'t post to a locked thread',
|
|
|
- postRemoved: 'You can\'t reply to a removed post',
|
|
|
+ unknown: ['An unknown error occured on our end. Please try again later', 500],
|
|
|
+ accountAlreadyCreated: ['This account has already been created', 400],
|
|
|
+ categoryAlreadyExists: ['This category has already been created', 400],
|
|
|
+ accountDoesNotExist: ['This account does not exist', 400],
|
|
|
+ invalidCategory: ['This category does not exist', 400],
|
|
|
+ invalidLoginCredentials: ['Invalid login credentials were provided', 401],
|
|
|
+ requestNotAuthorized: ['The request was not authorized', 401],
|
|
|
+ invalidToken: ['The token provided was not valid', 401],
|
|
|
+ noSettings: ['You haven\'t added any settings yet', 500],
|
|
|
+ passwordSame: ['You can\'t set it to the same password', 400],
|
|
|
+ cannotLikeOwnPost: ['You can\'t like your own post', 400],
|
|
|
+ threadLocked: ['You can\'t post to a locked thread', 400],
|
|
|
+ postRemoved: ['You can\'t reply to a removed post', 400],
|
|
|
invalidParameter (param, message) {
|
|
|
if(message) {
|
|
|
var punctuatedMessage = ': ' + message
|
|
|
}
|
|
|
|
|
|
- return `${param} is invalid${punctuatedMessage}`
|
|
|
+ return [`${param} is invalid${punctuatedMessage}`, 400]
|
|
|
},
|
|
|
missingParameter (param) {
|
|
|
- return `Missing ${param}`
|
|
|
+ return [`Missing ${param}`, 400]
|
|
|
},
|
|
|
invalidParameterType (param, type) {
|
|
|
- return `${param} must be of type ${type}`
|
|
|
+ return [`${param} must be of type ${type}`, 400]
|
|
|
},
|
|
|
parameterLengthTooSmall (param, length) {
|
|
|
- return `${param} must be more than ${length} characters in length`
|
|
|
+ return [`${param} must be more than ${length} characters in length`, 400]
|
|
|
},
|
|
|
parameterLengthTooLarge (param, length) {
|
|
|
- return `${param} must be less than ${length} characters in length`
|
|
|
+ return [`${param} must be less than ${length} characters in length`, 400]
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -39,17 +39,21 @@ function processErrors(errorName) {
|
|
|
|
|
|
if(typeof Errors[errorName] === 'function') {
|
|
|
temp = function() {
|
|
|
- let message = Errors[errorName](...arguments)
|
|
|
+ let arr = Errors[errorName](...arguments)
|
|
|
return {
|
|
|
name: errorName,
|
|
|
- message: message,
|
|
|
+ message: arr[0],
|
|
|
+ status: arr[1],
|
|
|
parameter: arguments[0]
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
+ let arr = Errors[errorName]
|
|
|
+
|
|
|
temp = {}
|
|
|
temp.name = errorName
|
|
|
- temp.message = Errors[errorName]
|
|
|
+ temp.message = arr[0]
|
|
|
+ temp.status = arr[1]
|
|
|
}
|
|
|
|
|
|
return temp
|