115 lines
No EOL
3.4 KiB
JavaScript
115 lines
No EOL
3.4 KiB
JavaScript
const getLoginMessageFromError = (json) => {
|
|
switch (json.message) {
|
|
case 'ERROR_REQUEST_LOGIN_INVALID': {
|
|
return 'Invalid username or password.';
|
|
}
|
|
|
|
case 'ERROR_ACCESS_DENIED': {
|
|
return 'You are not allowed to perform this action.'
|
|
}
|
|
|
|
default: {
|
|
return 'Unknown error. Something went wrong.'
|
|
}
|
|
}
|
|
}
|
|
|
|
const getSignupMessageFromError = (json) => {
|
|
switch (json.message) {
|
|
case 'ERROR_REQUEST_INVALID_DATA': {
|
|
|
|
switch (json.errors[0].param) {
|
|
case 'username': {
|
|
return 'Invalid username. Username must be between 3 and 32 characters long, and be alphanumeric.';
|
|
}
|
|
case 'password': {
|
|
return 'Invalid password. Password must be at least 8 characters long and at most 128 characters.';
|
|
}
|
|
case 'email': {
|
|
return 'Invalid email.';
|
|
}
|
|
case 'specialCode': {
|
|
return 'Invalid special code.';
|
|
}
|
|
|
|
default: {
|
|
return 'Invalid value sent to server. Something went wrong.';
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
case 'ERROR_ACCESS_DENIED': {
|
|
return 'You are not allowed to perform this action.'
|
|
}
|
|
|
|
case 'ERROR_REQUEST_USERNAME_EXISTS': {
|
|
return 'That username is taken.';
|
|
}
|
|
|
|
default: {
|
|
return 'Unknown error. Something went wrong.'
|
|
}
|
|
}
|
|
};
|
|
|
|
const getCreatePostError = (json) => {
|
|
switch (json.message) {
|
|
case 'ERROR_REQUEST_INVALID_DATA': {
|
|
switch (json.errors[0].param) {
|
|
case 'title': {
|
|
return 'Invalid title. Must be between 3 and 32 characters.';
|
|
}
|
|
case 'body': {
|
|
return 'Invalid content. Must be between 3 and 1000 characters';
|
|
}
|
|
case 'category': {
|
|
return 'Invalid category. Something went wrong.';
|
|
}
|
|
default: {
|
|
return 'Invalid value sent to server. Something went wrong.';
|
|
}
|
|
}
|
|
}
|
|
|
|
case 'ERROR_CATEGORY_NOT_FOUND': {
|
|
return 'The category you tried to post to no longer exists.';
|
|
}
|
|
|
|
case 'ERROR_ACCESS_DENIED': {
|
|
return 'You are not allowed to perform this action.'
|
|
}
|
|
|
|
default: {
|
|
return 'Unknown error. Something went wrong.';
|
|
}
|
|
}
|
|
};
|
|
|
|
const getCreateCategoryError = (json) => {
|
|
switch (json.message) {
|
|
case 'ERROR_REQUEST_INVALID_DATA': {
|
|
switch (json.errors[0].param) {
|
|
case 'title': {
|
|
return 'Invalid title. Title must be between 3 and 32 characters.';
|
|
}
|
|
|
|
default: {
|
|
return 'Invalid value sent to server. Something went wrong.'
|
|
}
|
|
}
|
|
}
|
|
|
|
case 'ERROR_ACCESS_DENIED': {
|
|
return 'You are not allowed to perform this action.'
|
|
}
|
|
|
|
default: {
|
|
return 'Unknown error. Something went wrong.';
|
|
}
|
|
}
|
|
};
|
|
|
|
const couldNotReach = "Whoops! We couldn't reach Brainlet."
|
|
|
|
module.exports = { couldNotReach, getLoginMessageFromError, getSignupMessageFromError, getCreatePostError, getCreateCategoryError } |