Add: More verbose errors

This commit is contained in:
Donatas Kirda 2024-05-20 12:14:05 +03:00
parent 816bcfc428
commit 7238d057b5
Signed by: bloodwiing
GPG Key ID: 63020D8D3F4A164F
4 changed files with 32 additions and 2 deletions

View File

@ -83,6 +83,8 @@ export async function getCategoryCached(category_id) {
return categories.get(category_id) || {
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,
};
}

View File

@ -203,32 +203,42 @@ export async function createPost(token, category, name, content) {
case 'message_require_user':
return {
error: true,
title: 'Bad session',
msg: 'User token was invalid',
expected: true,
};
case 'post_category_id_fkey':
return {
error: true,
title: 'Bad data',
msg: 'Post category does not exist',
expected: true,
};
case 'content_min_length':
return {
error: true,
title: 'Bad data',
msg: 'Post content cannot be empty',
expected: true,
};
case 'name_min_length':
return {
error: true,
title: 'Bad data',
msg: 'Post name cannot be empty',
expected: true,
};
default:
console.log(e);
return {
error: true,
title: 'Fail to process',
msg: 'Unknown error (notify dev)',
expected: false,
};
}

View File

@ -115,26 +115,34 @@ export async function createUser(username, password) {
case 'idx_user_username':
return {
error: true,
msg: "Username taken",
title: 'Already taken',
msg: "The Username has already been taken",
expected: true,
};
case 'username_length_min':
return {
error: true,
title: 'Bad data',
msg: "Username has invalid length",
expected: true,
};
case 'username_valid_symbols':
return {
error: true,
title: 'Bad data',
msg: "Username contains invalid symbols",
expected: true,
};
default:
console.log(e);
return {
error: true,
title: 'Fail to process',
msg: 'Unknown error (notify dev)',
expected: false,
};
}
}
@ -160,7 +168,9 @@ export async function createUserSession(username, password) {
if (result.length == 0) {
return {
error: true,
title: 'Invalid data',
msg: 'Username or password is incorrect',
expected: true,
};
}
@ -171,7 +181,9 @@ export async function createUserSession(username, password) {
if (!isMatch) {
return {
error: true,
title: 'Invalid data',
msg: 'Username or password is incorrect',
expected: true,
};
}
@ -203,7 +215,9 @@ export async function getUserIDOfSession(token) {
if (result.length == 0) {
return {
error: true,
title: 'Invalid session',
msg: "Invalid user session",
expected: true,
};
}
@ -225,7 +239,9 @@ export async function getUserOfSession(token) {
if (result.length == 0) {
return {
error: true,
title: 'Invalid session',
msg: "Invalid user session",
expected: true
};
}

View File

@ -1,6 +1,8 @@
export type Error = {
error: boolean,
title: string,
msg: string,
expected: boolean,
};
export type Success = {