summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-05-22 12:27:54 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-06-06 22:20:17 -0400
commit2cba0ada3cdf6b7ee37fa5c0b54134160be657a9 (patch)
tree38f6b59f7c60eda90677bc178974f71c877afe0d /packages/backend/src/server/api
parentrender error cause in render-inline-error.ts (diff)
downloadsharkey-2cba0ada3cdf6b7ee37fa5c0b54134160be657a9.tar.gz
sharkey-2cba0ada3cdf6b7ee37fa5c0b54134160be657a9.tar.bz2
sharkey-2cba0ada3cdf6b7ee37fa5c0b54134160be657a9.zip
more use of identifiable errors, improvements to inner error rendering, and more heuristics for is-retryable-error
Diffstat (limited to 'packages/backend/src/server/api')
-rw-r--r--packages/backend/src/server/api/SigninApiService.ts12
-rw-r--r--packages/backend/src/server/api/SignupApiService.ts16
-rw-r--r--packages/backend/src/server/api/endpoints/admin/relays/add.ts7
-rw-r--r--packages/backend/src/server/api/endpoints/gallery/posts/create.ts2
-rw-r--r--packages/backend/src/server/api/endpoints/gallery/posts/update.ts2
-rw-r--r--packages/backend/src/server/api/endpoints/i/2fa/remove-key.ts2
6 files changed, 19 insertions, 22 deletions
diff --git a/packages/backend/src/server/api/SigninApiService.ts b/packages/backend/src/server/api/SigninApiService.ts
index 7f371ea309..a53fec88d0 100644
--- a/packages/backend/src/server/api/SigninApiService.ts
+++ b/packages/backend/src/server/api/SigninApiService.ts
@@ -205,37 +205,37 @@ export class SigninApiService {
if (process.env.NODE_ENV !== 'test') {
if (this.meta.enableHcaptcha && this.meta.hcaptchaSecretKey) {
await this.captchaService.verifyHcaptcha(this.meta.hcaptchaSecretKey, body['hcaptcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableMcaptcha && this.meta.mcaptchaSecretKey && this.meta.mcaptchaSitekey && this.meta.mcaptchaInstanceUrl) {
await this.captchaService.verifyMcaptcha(this.meta.mcaptchaSecretKey, this.meta.mcaptchaSitekey, this.meta.mcaptchaInstanceUrl, body['m-captcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableFC && this.meta.fcSecretKey) {
await this.captchaService.verifyFriendlyCaptcha(this.meta.fcSecretKey, body['frc-captcha-solution']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableRecaptcha && this.meta.recaptchaSecretKey) {
await this.captchaService.verifyRecaptcha(this.meta.recaptchaSecretKey, body['g-recaptcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableTurnstile && this.meta.turnstileSecretKey) {
await this.captchaService.verifyTurnstile(this.meta.turnstileSecretKey, body['turnstile-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableTestcaptcha) {
await this.captchaService.verifyTestcaptcha(body['testcaptcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
}
diff --git a/packages/backend/src/server/api/SignupApiService.ts b/packages/backend/src/server/api/SignupApiService.ts
index cb71047a24..81e3a5b706 100644
--- a/packages/backend/src/server/api/SignupApiService.ts
+++ b/packages/backend/src/server/api/SignupApiService.ts
@@ -83,37 +83,37 @@ export class SignupApiService {
if (process.env.NODE_ENV !== 'test') {
if (this.meta.enableHcaptcha && this.meta.hcaptchaSecretKey) {
await this.captchaService.verifyHcaptcha(this.meta.hcaptchaSecretKey, body['hcaptcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableMcaptcha && this.meta.mcaptchaSecretKey && this.meta.mcaptchaSitekey && this.meta.mcaptchaInstanceUrl) {
await this.captchaService.verifyMcaptcha(this.meta.mcaptchaSecretKey, this.meta.mcaptchaSitekey, this.meta.mcaptchaInstanceUrl, body['m-captcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableRecaptcha && this.meta.recaptchaSecretKey) {
await this.captchaService.verifyRecaptcha(this.meta.recaptchaSecretKey, body['g-recaptcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableTurnstile && this.meta.turnstileSecretKey) {
await this.captchaService.verifyTurnstile(this.meta.turnstileSecretKey, body['turnstile-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableFC && this.meta.fcSecretKey) {
await this.captchaService.verifyFriendlyCaptcha(this.meta.fcSecretKey, body['frc-captcha-solution']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableTestcaptcha) {
await this.captchaService.verifyTestcaptcha(body['testcaptcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
}
@@ -287,7 +287,7 @@ export class SignupApiService {
token: secret,
};
} catch (err) {
- throw new FastifyReplyError(400, typeof err === 'string' ? err : (err as Error).toString());
+ throw new FastifyReplyError(400, String(err), err);
}
}
}
@@ -356,7 +356,7 @@ export class SignupApiService {
return this.signinService.signin(request, reply, account as MiLocalUser);
} catch (err) {
- throw new FastifyReplyError(400, typeof err === 'string' ? err : (err as Error).toString());
+ throw new FastifyReplyError(400, String(err), err);
}
}
}
diff --git a/packages/backend/src/server/api/endpoints/admin/relays/add.ts b/packages/backend/src/server/api/endpoints/admin/relays/add.ts
index 129f69aca9..4644a069ee 100644
--- a/packages/backend/src/server/api/endpoints/admin/relays/add.ts
+++ b/packages/backend/src/server/api/endpoints/admin/relays/add.ts
@@ -68,11 +68,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private readonly moderationLogService: ModerationLogService,
) {
super(meta, paramDef, async (ps, me) => {
- try {
- if (new URL(ps.inbox).protocol !== 'https:') throw new Error('https only');
- } catch {
- throw new ApiError(meta.errors.invalidUrl);
- }
+ if (!URL.canParse(ps.inbox)) throw new ApiError(meta.errors.invalidUrl);
+ if (new URL(ps.inbox).protocol !== 'https:') throw new ApiError(meta.errors.invalidUrl);
await this.moderationLogService.log(me, 'addRelay', {
inbox: ps.inbox,
diff --git a/packages/backend/src/server/api/endpoints/gallery/posts/create.ts b/packages/backend/src/server/api/endpoints/gallery/posts/create.ts
index 504a9c789e..08abd7fed5 100644
--- a/packages/backend/src/server/api/endpoints/gallery/posts/create.ts
+++ b/packages/backend/src/server/api/endpoints/gallery/posts/create.ts
@@ -72,7 +72,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
))).filter(x => x != null);
if (files.length === 0) {
- throw new Error();
+ throw new Error('no files specified');
}
const post = await this.galleryPostsRepository.insertOne(new MiGalleryPost({
diff --git a/packages/backend/src/server/api/endpoints/gallery/posts/update.ts b/packages/backend/src/server/api/endpoints/gallery/posts/update.ts
index 5243ee9603..d0f9b56863 100644
--- a/packages/backend/src/server/api/endpoints/gallery/posts/update.ts
+++ b/packages/backend/src/server/api/endpoints/gallery/posts/update.ts
@@ -73,7 +73,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
))).filter(x => x != null);
if (files.length === 0) {
- throw new Error();
+ throw new Error('no files');
}
}
diff --git a/packages/backend/src/server/api/endpoints/i/2fa/remove-key.ts b/packages/backend/src/server/api/endpoints/i/2fa/remove-key.ts
index d4098458d7..931c8d69b0 100644
--- a/packages/backend/src/server/api/endpoints/i/2fa/remove-key.ts
+++ b/packages/backend/src/server/api/endpoints/i/2fa/remove-key.ts
@@ -70,7 +70,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
try {
await this.userAuthService.twoFactorAuthenticate(profile, token);
} catch (e) {
- throw new Error('authentication failed');
+ throw new Error('authentication failed', { cause: e });
}
}