Skip to content

Commit e5be109

Browse files
committed
feat: change json to html error page
1 parent ced9a13 commit e5be109

File tree

1 file changed

+57
-6
lines changed

1 file changed

+57
-6
lines changed

packages/botkit/src/pages.tsx

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,25 @@ app.get("/feed.xml", async (c) => {
436436
app.post("/follow", async (c) => {
437437
const { bot } = c.env;
438438
const ctx = bot.federation.createContext(c.req.raw, c.env.contextData);
439+
const url = new URL(c.req.url);
439440

440441
const formData = await c.req.formData();
441442
let followerHandle = formData.get("handle")?.toString();
442443

443444
try {
444445
if (!followerHandle) {
445-
return c.json({ error: "Follower handle is required." }, 400);
446+
return c.html(
447+
<Layout bot={bot} host={url.host} title="Error">
448+
<main class="container">
449+
<h1>Error</h1>
450+
<p>Follower handle is required.</p>
451+
<p>
452+
<a href="/">Go back</a>
453+
</p>
454+
</main>
455+
</Layout>,
456+
400,
457+
);
446458
}
447459

448460
if (followerHandle.startsWith("@")) {
@@ -453,7 +465,21 @@ app.post("/follow", async (c) => {
453465
.lookupWebFinger(`acct:${followerHandle}`);
454466

455467
if (!webfingerData?.links) {
456-
return c.json({ error: "No links found in webfinger data" }, 400);
468+
return c.html(
469+
<Layout bot={bot} host={url.host} title="Error">
470+
<main class="container">
471+
<h1>Error</h1>
472+
<p>
473+
No links found in webfinger data for{" "}
474+
<code>@{followerHandle}</code>.
475+
</p>
476+
<p>
477+
<a href="/">Go back</a>
478+
</p>
479+
</main>
480+
</Layout>,
481+
400,
482+
);
457483
}
458484

459485
const subscribeLink = webfingerData.links.find(
@@ -469,11 +495,36 @@ app.post("/follow", async (c) => {
469495
return c.redirect(followUrl);
470496
}
471497

472-
return c.json({
473-
error: "No follow link found in WebFinger data.",
474-
}, 400);
498+
return c.html(
499+
<Layout bot={bot} host={url.host} title="Error">
500+
<main class="container">
501+
<h1>Error</h1>
502+
<p>
503+
No follow link found in WebFinger data for{" "}
504+
<code>@{followerHandle}</code>.
505+
</p>
506+
<p>
507+
<a href="/">Go back</a>
508+
</p>
509+
</main>
510+
</Layout>,
511+
400,
512+
);
475513
} catch (_error) {
476-
return c.json({ error: "An internal server error occurred." }, 500);
514+
return c.html(
515+
<Layout bot={bot} host={url.host} title="Error">
516+
<main class="container">
517+
<h1>Internal Server Error</h1>
518+
<p>
519+
An internal server error occurred while processing your request.
520+
</p>
521+
<p>
522+
<a href="/">Go back</a>
523+
</p>
524+
</main>
525+
</Layout>,
526+
500,
527+
);
477528
}
478529
});
479530

0 commit comments

Comments
 (0)