Add: More verbose errors
This commit is contained in:
parent
816bcfc428
commit
7238d057b5
@ -83,6 +83,8 @@ export async function getCategoryCached(category_id) {
|
|||||||
|
|
||||||
return categories.get(category_id) || {
|
return categories.get(category_id) || {
|
||||||
error: true,
|
error: true,
|
||||||
msg: `Could not find Category of ID ${category_id}`
|
title: 'Not found',
|
||||||
|
msg: `Could not find Category of ID ${category_id}`,
|
||||||
|
expected: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -203,32 +203,42 @@ export async function createPost(token, category, name, content) {
|
|||||||
case 'message_require_user':
|
case 'message_require_user':
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
title: 'Bad session',
|
||||||
msg: 'User token was invalid',
|
msg: 'User token was invalid',
|
||||||
|
expected: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
case 'post_category_id_fkey':
|
case 'post_category_id_fkey':
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
title: 'Bad data',
|
||||||
msg: 'Post category does not exist',
|
msg: 'Post category does not exist',
|
||||||
|
expected: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
case 'content_min_length':
|
case 'content_min_length':
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
title: 'Bad data',
|
||||||
msg: 'Post content cannot be empty',
|
msg: 'Post content cannot be empty',
|
||||||
|
expected: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
case 'name_min_length':
|
case 'name_min_length':
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
title: 'Bad data',
|
||||||
msg: 'Post name cannot be empty',
|
msg: 'Post name cannot be empty',
|
||||||
|
expected: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log(e);
|
console.log(e);
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
title: 'Fail to process',
|
||||||
msg: 'Unknown error (notify dev)',
|
msg: 'Unknown error (notify dev)',
|
||||||
|
expected: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -115,26 +115,34 @@ export async function createUser(username, password) {
|
|||||||
case 'idx_user_username':
|
case 'idx_user_username':
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
msg: "Username taken",
|
title: 'Already taken',
|
||||||
|
msg: "The Username has already been taken",
|
||||||
|
expected: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
case 'username_length_min':
|
case 'username_length_min':
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
title: 'Bad data',
|
||||||
msg: "Username has invalid length",
|
msg: "Username has invalid length",
|
||||||
|
expected: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
case 'username_valid_symbols':
|
case 'username_valid_symbols':
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
title: 'Bad data',
|
||||||
msg: "Username contains invalid symbols",
|
msg: "Username contains invalid symbols",
|
||||||
|
expected: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log(e);
|
console.log(e);
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
title: 'Fail to process',
|
||||||
msg: 'Unknown error (notify dev)',
|
msg: 'Unknown error (notify dev)',
|
||||||
|
expected: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,7 +168,9 @@ export async function createUserSession(username, password) {
|
|||||||
if (result.length == 0) {
|
if (result.length == 0) {
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
title: 'Invalid data',
|
||||||
msg: 'Username or password is incorrect',
|
msg: 'Username or password is incorrect',
|
||||||
|
expected: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +181,9 @@ export async function createUserSession(username, password) {
|
|||||||
if (!isMatch) {
|
if (!isMatch) {
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
title: 'Invalid data',
|
||||||
msg: 'Username or password is incorrect',
|
msg: 'Username or password is incorrect',
|
||||||
|
expected: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +215,9 @@ export async function getUserIDOfSession(token) {
|
|||||||
if (result.length == 0) {
|
if (result.length == 0) {
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
title: 'Invalid session',
|
||||||
msg: "Invalid user session",
|
msg: "Invalid user session",
|
||||||
|
expected: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +239,9 @@ export async function getUserOfSession(token) {
|
|||||||
if (result.length == 0) {
|
if (result.length == 0) {
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
title: 'Invalid session',
|
||||||
msg: "Invalid user session",
|
msg: "Invalid user session",
|
||||||
|
expected: true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
export type Error = {
|
export type Error = {
|
||||||
error: boolean,
|
error: boolean,
|
||||||
|
title: string,
|
||||||
msg: string,
|
msg: string,
|
||||||
|
expected: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Success = {
|
export type Success = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user