emit IdentifiableErrors from validator.ts
This commit is contained in:
parent
24b0d7a376
commit
f644972760
2 changed files with 9 additions and 4 deletions
|
|
@ -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}`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue