summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-03-03 00:46:48 -0500
committerHazelnoot <acomputerdog@gmail.com>2025-06-06 22:19:49 -0400
commitf6449727601ecfa960e0dce1ff0e38e3581c0d3e (patch)
tree5f7ddca99c19a43faa5be64b055c2384b6e8368c /packages/backend/src
parentmerge: Fix performance regression in URL previews (resoles #1091) (!1096) (diff)
downloadsharkey-f6449727601ecfa960e0dce1ff0e38e3581c0d3e.tar.gz
sharkey-f6449727601ecfa960e0dce1ff0e38e3581c0d3e.tar.bz2
sharkey-f6449727601ecfa960e0dce1ff0e38e3581c0d3e.zip
emit IdentifiableErrors from validator.ts
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/core/activitypub/misc/validator.ts9
-rw-r--r--packages/backend/src/server/api/endpoints/ap/show.ts4
2 files changed, 9 insertions, 4 deletions
diff --git a/packages/backend/src/core/activitypub/misc/validator.ts b/packages/backend/src/core/activitypub/misc/validator.ts
index 0ff83659c1..d2f2354918 100644
--- a/packages/backend/src/core/activitypub/misc/validator.ts
+++ b/packages/backend/src/core/activitypub/misc/validator.ts
@@ -3,6 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
+import { IdentifiableError } from '@/misc/identifiable-error.js';
import type { Response } from 'node-fetch';
// TODO throw identifiable or unrecoverable errors
@@ -11,7 +12,7 @@ export function validateContentTypeSetAsActivityPub(response: Response): void {
const contentType = (response.headers.get('content-type') ?? '').toLowerCase();
if (contentType === '') {
- throw new Error(`invalid content type of AP response - no content-type header: ${response.url}`);
+ throw new IdentifiableError('d09dc850-b76c-4f45-875a-7389339d78b8', `invalid content type of AP response - no content-type header: ${response.url}`, true);
}
if (
contentType.startsWith('application/activity+json') ||
@@ -19,7 +20,7 @@ export function validateContentTypeSetAsActivityPub(response: Response): void {
) {
return;
}
- throw new Error(`invalid content type of AP response - content type is not application/activity+json or application/ld+json: ${response.url}`);
+ throw new IdentifiableError('dc110060-a5f2-461d-808b-39c62702ca64', `invalid content type of AP response - content type "${contentType}" is not application/activity+json or application/ld+json: ${response.url}`);
}
const plusJsonSuffixRegex = /^\s*(application|text)\/[a-zA-Z0-9\.\-\+]+\+json\s*(;|$)/;
@@ -28,7 +29,7 @@ export function validateContentTypeSetAsJsonLD(response: Response): void {
const contentType = (response.headers.get('content-type') ?? '').toLowerCase();
if (contentType === '') {
- throw new Error(`invalid content type of JSON LD - no content-type header: ${response.url}`);
+ throw new IdentifiableError('45793ab7-7648-4886-b503-429f8a0d0f73', `invalid content type of JSON LD - no content-type header: ${response.url}`, true);
}
if (
contentType.startsWith('application/ld+json') ||
@@ -37,5 +38,5 @@ export function validateContentTypeSetAsJsonLD(response: Response): void {
) {
return;
}
- throw new Error(`invalid content type of JSON LD - content type is not application/ld+json or application/json: ${response.url}`);
+ throw new IdentifiableError('4bf8f36b-4d33-4ac9-ad76-63fa11f354e9', `invalid content type of JSON LD - content type "${contentType}" is not application/ld+json or application/json: ${response.url}`);
}
diff --git a/packages/backend/src/server/api/endpoints/ap/show.ts b/packages/backend/src/server/api/endpoints/ap/show.ts
index d69850515c..d631b002cc 100644
--- a/packages/backend/src/server/api/endpoints/ap/show.ts
+++ b/packages/backend/src/server/api/endpoints/ap/show.ts
@@ -173,6 +173,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
case '09d79f9e-64f1-4316-9cfa-e75c4d091574':
throw new ApiError(meta.errors.federationNotAllowed);
case '72180409-793c-4973-868e-5a118eb5519b':
+ case 'd09dc850-b76c-4f45-875a-7389339d78b8':
+ case 'dc110060-a5f2-461d-808b-39c62702ca64':
+ case '45793ab7-7648-4886-b503-429f8a0d0f73':
+ case '4bf8f36b-4d33-4ac9-ad76-63fa11f354e9':
throw new ApiError(meta.errors.responseInvalid);
// resolveLocal