Skip to content

Commit

Permalink
fix: dont use Response.json
Browse files Browse the repository at this point in the history
  • Loading branch information
olros committed Apr 26, 2024
1 parent f4cfbf7 commit 4725006
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions web/app/routes/api-internal.$teamSlug.$projectSlug.event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { CustomEventInput } from '~/types';
const parseCustomEventInput = async (request: Request): Promise<CustomEventInput> => {
const data = (await request.json()) as CustomEventInput;
if (!data.name) {
throw Response.json({ errors: { name: `Name isn't defined` } }, { status: 400 });
throw new Response(JSON.stringify({ errors: { name: `Name isn't defined` } }), { status: 400 });
}

return data;
Expand Down Expand Up @@ -59,9 +59,9 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {

await trackCustomEvent(request, project);

return Response.json({ ok: true }, { status: 200 });
return new Response(JSON.stringify({ ok: true }), { status: 200 });
} catch (e) {
console.error('[API-Internal - Event]', e);
return Response.json({ ok: false }, { status: 400 });
return new Response(JSON.stringify({ ok: false }), { status: 400 });
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
await trackPageviewNext(request, project);
} catch (e) {
console.error('[API-Internal - PageviewNext]', e);
return Response.json({ ok: false }, { status: 400 });
return new Response(JSON.stringify({ ok: false }), { status: 400 });
}
return Response.json({ ok: true }, { status: 200 });
return new Response(JSON.stringify({ ok: true }), { status: 200 });
};
4 changes: 2 additions & 2 deletions web/app/routes/api.$teamSlug.$projectSlug.event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export const action = async ({ request, params, context }: ActionFunctionArgs) =
} else {
await forwardRequestToInternalApi(request, `${params.teamSlug}/${params.projectSlug}/event/`);
}
return Response.json({ ok: true }, { status: 200 });
return new Response(JSON.stringify({ ok: true }), { status: 200 });
} catch (e) {
console.error('[API - Event]', e);
return Response.json({ ok: false }, { status: 400 });
return new Response(JSON.stringify({ ok: false }), { status: 400 });
}
};
8 changes: 4 additions & 4 deletions web/app/routes/api.$teamSlug.$projectSlug.pageview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import invariant from 'tiny-invariant';

import type { PageviewInput } from '~/types';

import type { PageviewRequestData } from './api-internal.$teamSlug.$projectSlug.pageview-next';
import type { PageviewRequestData } from './api-internal.$teamSlug.$projectSlug.pageview';

export const config = { runtime: 'edge' };

Expand Down Expand Up @@ -86,7 +86,7 @@ export const action = async ({ request, params, context }: ActionFunctionArgs) =
const pageViewNextRequest = await getPageViewNextRequest(request);

const promises = Promise.all([
...(pageViewNextRequest ? [forwardRequestToInternalApi(pageViewNextRequest, `${params.teamSlug}/${params.projectSlug}/pageview-next/`)] : []),
...(pageViewNextRequest ? [forwardRequestToInternalApi(pageViewNextRequest, `${params.teamSlug}/${params.projectSlug}/pageview/`)] : []),
]);

if ('waitUntil' in ctx) {
Expand All @@ -96,7 +96,7 @@ export const action = async ({ request, params, context }: ActionFunctionArgs) =
}
} catch (e) {
console.error('[API - Pageview]', e);
return Response.json({ ok: false }, { status: 400 });
return new Response(JSON.stringify({ ok: false }), { status: 400 });
}
return Response.json({ ok: true }, { status: 200 });
return new Response(JSON.stringify({ ok: true }), { status: 200 });
};

0 comments on commit 4725006

Please sign in to comment.