wrap whole thing in a try catch to try to be safe
This commit is contained in:
7
mod.ts
7
mod.ts
@@ -20,6 +20,7 @@ const genericResponse = (status: StatusCode, customText = '') =>
|
||||
new Response(customText || STATUS_TEXT[status], { status: status, statusText: STATUS_TEXT[status] });
|
||||
|
||||
Deno.serve({ port: config.api.port }, async (req) => {
|
||||
try {
|
||||
const urlPath = req.url.split('?')[0] ?? '';
|
||||
let rawPath = (urlPath.split('api')[1] ?? '').trim();
|
||||
if (rawPath.endsWith('/')) rawPath = rawPath.slice(0, -1);
|
||||
@@ -38,7 +39,8 @@ Deno.serve({ port: config.api.port }, async (req) => {
|
||||
if (failed) return genericResponse(STATUS_CODE.InternalServerError, "Couldn't read DB.");
|
||||
|
||||
if (userNameMatches.length === 0) {
|
||||
if (body.name.length < 4 || body.name.length > 20) return genericResponse(STATUS_CODE.BadRequest, `Name too ${body.name.length < 4 ? 'short' : 'long'}.`);
|
||||
if (body.name.length < 4 || body.name.length > 20)
|
||||
return genericResponse(STATUS_CODE.BadRequest, `Name too ${body.name.length < 4 ? 'short' : 'long'}.`);
|
||||
if (body.pin.length < 4 || body.pin.length > 20) return genericResponse(STATUS_CODE.BadRequest, `PIN too ${body.pin.length < 4 ? 'short' : 'long'}.`);
|
||||
if (body.email.length > 255) return genericResponse(STATUS_CODE.BadRequest, `Email too long.`);
|
||||
|
||||
@@ -177,4 +179,7 @@ Deno.serve({ port: config.api.port }, async (req) => {
|
||||
}
|
||||
|
||||
return genericResponse(STATUS_CODE.NotImplemented);
|
||||
} catch (_e) {
|
||||
return genericResponse(STATUS_CODE.InternalServerError);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user