feat: add parsable error handling to api methods

This commit is contained in:
mrjvs
2026-08-11 20:31:42 +02:00
parent f98a244606
commit 95cefec5c2
12 changed files with 128 additions and 37 deletions

18
server/utils/errors.ts Normal file
View File

@@ -0,0 +1,18 @@
import { apiErrorCodeStatus, getTextForApiErrorCode } from '~~/shared/errors';
import type { ApiErrorCodes, ApiError } from '~~/shared/errors';
export function createApiError(code: ApiErrorCodes) {
const err = createApiErrorBase(code);
return createError({
statusCode: apiErrorCodeStatus[err.code],
message: err.message,
data: err
});
}
export function createApiErrorBase(code: ApiErrorCodes): ApiError {
return {
code,
message: getTextForApiErrorCode(code)
};
}

View File

@@ -13,7 +13,7 @@ export async function hcaptchaVerify(event: H3Event, captchaResponse: string | n
if (!captchaResponse) {
return false;
} // No captcha filled in, invalid
const captchaVerify = await hcaptcha.verify(config.hcaptchaSiteKey, captchaResponse, undefined, config.hcaptchaSiteKey);
const captchaVerify = await hcaptcha.verify(config.hcaptchaSecretKey, captchaResponse, undefined, config.public.hcaptchaSiteKey);
if (!captchaVerify.success) {
return false;