add error handling to the one route we need it in

This commit is contained in:
Joonas 2023-02-18 14:09:57 +02:00
parent fd6b3a73fc
commit 0bdab37f2e
2 changed files with 21 additions and 8 deletions

View File

@ -16,14 +16,23 @@ export function Command() {
) : ( ) : (
"" ""
)} )}
<h1 className="mb-2 border-b pb-2 text-center text-4xl tracking-tighter">
{data.name} {data.error ? (
</h1> <div className="rounded-lg bg-red-600 p-6 text-white shadow-lg">
<div className="space-y-1 p-4"> <h1>Error: {data.error}</h1>
<p className="font-semibold">{data.desc}</p> </div>
<p>Only for privlidged: {data.restricted.toString()}</p> ) : (
<p>Needs mod: {data.mod.toString()}</p> <>
</div> <h1 className="mb-2 border-b pb-2 text-center text-4xl tracking-tighter">
{data.name}
</h1>
<div className="space-y-1 p-4">
<p className="font-semibold">{data.desc}</p>
<p>Only for privlidged: {data.restricted.toString()}</p>
<p>Needs mod: {data.mod.toString()}</p>
</div>
</>
)}
</div> </div>
); );
} }

View File

@ -12,6 +12,10 @@ fastify.get("/api/v1/commands", (req, res) => {
}); });
fastify.get("/api/v1/commands/:name", (req, res) => { fastify.get("/api/v1/commands/:name", (req, res) => {
if (!(req.params.name in client.commands)) {
return { error: "Command not found" };
}
return client.commands[req.params.name]; return client.commands[req.params.name];
}); });