cubash-archive/lib/errors.js

200 lines
4.5 KiB
JavaScript

let Errors = {
unknown: [
'Uh oh! Something went wrong. Please contact a Kaverti staff member for assistance.',
500
],
accountAlreadyCreated: [
'This account has already been created',
400
],
categoryAlreadyExists: [
'This category has already been created',
400
],
ReadOnlyMode: [
'You may not perform this action while in Read-Only mode.',
400
],
LoginRequired: [
'Due to the nature of this action, a login is required.',
401
],
deniedExperiments: [
'Please enable integration developer mode to access experiments.',
401
],
reCAPTCHA: [
'Oh uh! You failed the reCAPTCHA score, please try again or contact support! This could be caused because you are operating the API through an unofficial client, CLI application, or reCAPTCHA is blocked by your network administrator or ISP.',
400
],
containsProfanityGeneric: [
'Please remove profanity from your input',
400
],
deniedWebsiteAccess: [
'This category has already been created',
400
],
accountDoesNotExist: [
'This account does not exist',
400
],
botOnlyEndpoint: [
'This endpoint is only available for bot accounts.'
],
invalidCategory: [
'This category does not exist',
400
],
invalidLoginCredentials: [
'The username or password provided was incorrect',
401
],
requestNotAuthorized: [
'You aren\'t logged in, or you don\'t have permission to perform this action.',
401
],
verifyEmail: [
'You need to verify your email first before you can use this Kaverti feature.',
401
],
invalidToken: [
'Your QACT (Quick Admin Creation Token) is invalid.',
401
],
passwordResetOptOut: [
'User has opted out of password resets.',
401
],
invalidPasswordToken: [
'This account recovery token is invalid.',
401
],
passwordResetDisabled: [
'This account has password resets disabled (This account has already reset their password, or hasn\'t ever reset their password.).',
401
],
featureDisabled: [
'This feature has been disabled, or is coming soon.',
401
],
featureDisabledState: [
'Administrators can no longer modify state. [Feature Disabled]',
401
],
noLongerHiring: [
'Sorry! We\'re no longer hiring staff right now.',
401
],
invalidPassKey: [
'Your PassKey is invalid.',
401
],
invalidEmailToken: [
'Your email token is invalid.',
401
],
alreadyVerified: [
'You have already verified your email.',
401
],
modifyAdminUser: [
'You cannot edit admin users.',
401
],
noSettings: [
'This Kaverti node has been incorrectly configured.',
500
],
registrationsDisabled: [
'Registrations are disabled, Kaverti is using PassKey\'s, if you would like an registration URL, please boost the Kaverti Discord server, If you think this was a mistake please contact an Kaverti administrator.',
400
],
selectCategory: [
'Please select a category.',
400
],
renderingFailure: [
'Something went wrong rendering your avatar, please try again later, or contact a Kaverti staff member.',
500
],
koinFail: [
'You can only get Koins from this method once a day.',
500
],
lockedCategory: [
'This category is locked, only admins can post here, however, you can still respond to existing threads if they aren\'t locked',
400
],
passwordSame: [
'What\'s the point of changing your password if you\'re going to change it to what it already is.',
400
],
cannotLikeOwnPost: [
'You can\'t like your own post',
400
],
threadLocked: [
'Uh, You can\'t reply to a locked thread, bruh.',
400
],
threadTitleMaxLimit: [
'Thread title is over 50 characters.',
400
],
postRemoved: [
'The original posters must\'ve deleted their post, so you cannot respond to it!',
400
]
}
function processErrors(errorName) {
let arr = Errors[errorName]
temp = {}
temp.name = errorName
temp.message = arr[0]
temp.status = arr[1]
return {
name: errorName,
message: arr[0],
status: arr[1]
}
}
let ProcessedErrors = {}
for(let errorName in Errors) {
ProcessedErrors[errorName] = processErrors(errorName)
}
ProcessedErrors.VALIDATION_ERROR = 'VALIDATION_ERROR';
ProcessedErrors.invalidParameter = function (param, message) {
let punctuatedMessage = '';
if(message) {
punctuatedMessage = ': ' + message;
}
return {
name: 'invalidParameter',
message: `${param} is invalid${punctuatedMessage}`,
status: 400,
parameter: param
};
}
ProcessedErrors.sequelizeValidation = (sequelize, obj) => {
return new sequelize.ValidationError(obj.error, [
new sequelize.ValidationErrorItem(
obj.error,
'Validation error',
obj.path,
obj.value
)
])
}
module.exports = ProcessedErrors