mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-09-08 08:56:39 -05:00
feat: add parsable error handling to api methods
This commit is contained in:
@@ -7,10 +7,7 @@ export default defineEventHandler(async (event): Promise<void> => {
|
||||
|
||||
const captchaResult = await hcaptchaVerify(event, body.captchaResponse);
|
||||
if (!captchaResult) {
|
||||
throw createError({
|
||||
status: 400,
|
||||
message: 'Invalid captcha'
|
||||
});
|
||||
throw createApiError('INVALID_CAPTCHA');
|
||||
}
|
||||
|
||||
await grpc.forgotPassword({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ServerError } from 'nice-grpc';
|
||||
import { ClientError } from 'nice-grpc';
|
||||
import { LoginSchema } from '#shared/api-types';
|
||||
import type { ApiAuthLogin } from '#shared/api-types';
|
||||
|
||||
@@ -18,18 +18,12 @@ export default defineEventHandler(async (event): Promise<ApiAuthLogin> => {
|
||||
refreshToken: res.refreshToken
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof ServerError) {
|
||||
if (error instanceof ClientError) {
|
||||
if (error.details === 'INVALID_ARGUMENT: User not found') {
|
||||
throw createError({
|
||||
status: 400,
|
||||
message: 'User not found'
|
||||
});
|
||||
throw createApiError('INVALID_USERNAME');
|
||||
}
|
||||
if (error.details === 'INVALID_ARGUMENT: Password is incorrect') {
|
||||
throw createError({
|
||||
status: 400,
|
||||
message: 'Password was incorrect'
|
||||
});
|
||||
throw createApiError('INVALID_PASSWORD');
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user