aboutsummaryrefslogtreecommitdiff
path: root/apps/web/app/api
diff options
context:
space:
mode:
authorDhravya Shah <[email protected]>2024-08-03 16:09:39 -0700
committerDhravya Shah <[email protected]>2024-08-03 16:09:39 -0700
commite30e9f4e0bb5a11786495445f548d40f3d08f70a (patch)
tree586434698406d4aa343ce75b31bfdc1e2632abeb /apps/web/app/api
parenthandle errors properly (diff)
downloadsupermemory-e30e9f4e0bb5a11786495445f548d40f3d08f70a.tar.xz
supermemory-e30e9f4e0bb5a11786495445f548d40f3d08f70a.zip
fix: stuff
Diffstat (limited to 'apps/web/app/api')
-rw-r--r--apps/web/app/api/store/route.ts39
1 files changed, 31 insertions, 8 deletions
diff --git a/apps/web/app/api/store/route.ts b/apps/web/app/api/store/route.ts
index 6efbab8f..ad81c7c4 100644
--- a/apps/web/app/api/store/route.ts
+++ b/apps/web/app/api/store/route.ts
@@ -2,6 +2,7 @@ import { type NextRequest } from "next/server";
import { addFromAPIType } from "@repo/shared-types";
import { ensureAuth } from "../ensureAuth";
import { createMemoryFromAPI } from "./helper";
+import { getRawTweet } from "@repo/shared-types/utils";
export const runtime = "edge";
@@ -22,14 +23,36 @@ export async function POST(req: NextRequest) {
body = await req.json();
} catch (e) {
const error = (e as Error).message;
- return new Response(
- JSON.stringify({
- message: "A JSON was not sent to the API. " + error,
- }),
- {
- status: 400,
- },
- );
+
+ console.log(error);
+
+ const tryJson = getRawTweet(await req.text());
+ console.log(tryJson);
+
+ if (tryJson) {
+ try {
+ body = JSON.parse(tryJson);
+ } catch (e) {
+ console.log(e);
+ return new Response(
+ JSON.stringify({
+ message: "Raw found but not json?" + error,
+ }),
+ {
+ status: 400,
+ },
+ );
+ }
+ } else {
+ return new Response(
+ JSON.stringify({
+ message: "Raw not found & not json." + error,
+ }),
+ {
+ status: 400,
+ },
+ );
+ }
}
const validated = addFromAPIType.safeParse(body);