mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-09-10 01:46:34 -05:00
feat: add parsable error handling to api methods
This commit is contained in:
18
server/utils/errors.ts
Normal file
18
server/utils/errors.ts
Normal 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)
|
||||
};
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user