mirror of
https://github.com/graphql-hive/console
synced 2026-04-21 14:37:17 +00:00
fix(lambda): gracefully handle cases where event URL is not valid (#7713)
This commit is contained in:
parent
78ef8c08a6
commit
6e4a2177f4
1 changed files with 19 additions and 1 deletions
|
|
@ -51,12 +51,30 @@ const artifactHandler = createArtifactRequestHandler({
|
|||
|
||||
const artifactRouteHandler = createServerAdapter(artifactHandler as any);
|
||||
|
||||
function tryParseEventUrl(rawPath: string): URL | null {
|
||||
try {
|
||||
return new URL(rawPath, 'http://localhost');
|
||||
} catch (e) {
|
||||
console.error(`Failed to parse URL: ${rawPath}`, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function handler(
|
||||
event: APIGatewayProxyEventV2,
|
||||
lambdaContext: Context,
|
||||
): Promise<APIGatewayProxyResult> {
|
||||
console.log(event.requestContext.http.method, event.rawPath);
|
||||
const url = new URL(event.rawPath, 'http://localhost');
|
||||
const url = tryParseEventUrl(event.rawPath);
|
||||
|
||||
if (!url) {
|
||||
return {
|
||||
statusCode: 400,
|
||||
body: 'Invalid URL',
|
||||
isBase64Encoded: false,
|
||||
};
|
||||
}
|
||||
|
||||
if (event.queryStringParameters != null) {
|
||||
for (const name in event.queryStringParameters) {
|
||||
const value = event.queryStringParameters[name];
|
||||
|
|
|
|||
Loading…
Reference in a new issue