Fix invalid claims ending up with status 500 (#1678)

## Issue
Due the `parseUri` not being used in a try-catch block, the thrown error surfaces all the way up and the 500 catch-all status was used.

The search console was been complaining about this for a while now. I've always thought "what's the problem here, you entered the wrong claim format", but now I realized it's about the error code.

## Change
`try-catch` the call as normal for that function, and return 404. We will still relay the error message it was.
This commit is contained in:
infinite-persistence 2022-06-13 20:55:45 +08:00 committed by GitHub
parent 075b8bcf62
commit 60f48b1a3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -380,8 +380,16 @@ async function getHtml(ctx) {
}
if (!requestPath.includes('$')) {
const parsedUri = parseURI(normalizeClaimUrl(requestPath.slice(1)));
const claimUri = buildURI({ ...parsedUri, startTime: undefined });
let parsedUri, claimUri;
try {
parsedUri = parseURI(normalizeClaimUrl(requestPath.slice(1)));
claimUri = buildURI({ ...parsedUri, startTime: undefined });
} catch (err) {
ctx.status = 404;
return err.message;
}
const claim = await resolveClaimOrRedirect(ctx, claimUri);
const referrerQuery = escapeHtmlProperty(getParameterByName('r', ctx.request.url));