diff --git a/api/src/core/api.js b/api/src/core/api.js index a1c2692a..fb55d35a 100644 --- a/api/src/core/api.js +++ b/api/src/core/api.js @@ -65,7 +65,7 @@ export function runAPI(express, app, __dirname) { }, handler: (req, res) => { const { status, body } = createResponse("error", { - code: "error.rate_exceeded", + code: "error.api.rate_exceeded", context: { limit: env.rateLimitWindow } @@ -122,11 +122,11 @@ export function runAPI(express, app, __dirname) { } if (!acceptRegex.test(req.header('Accept'))) { - return fail(res, 'ErrorInvalidAcceptHeader'); + return fail(res, "error.api.header.accept"); } if (!acceptRegex.test(req.header('Content-Type'))) { - return fail(res, 'ErrorInvalidContentType'); + return fail(res, "error.api.header.content_type"); } req.authorized = true; @@ -152,10 +152,7 @@ export function runAPI(express, app, __dirname) { app.use('/', (err, _, res, next) => { if (err) { const { status, body } = createResponse("error", { - code: "error.body_invalid", - context: { - limit: env.rateLimitWindow - } + code: "error.api.invalid_body", }); return res.status(status).json(body); } @@ -195,7 +192,7 @@ export function runAPI(express, app, __dirname) { const lang = languageCode(req); if (!request.url) { - return fail(res, 'ErrorNoLink'); + return fail(res, "error.api.link.missing"); } if (request.youtubeDubBrowserLang) { @@ -204,12 +201,12 @@ export function runAPI(express, app, __dirname) { const { success, data: normalizedRequest } = await normalizeRequest(request); if (!success) { - return fail(res, 'ErrorCantProcess'); + return fail(res, "error.api.invalid_body"); } const parsed = extract(normalizedRequest.url); if (parsed === null) { - return fail(res, 'ErrorUnsupported'); + return fail(res, "error.api.service.unsupported"); } try { @@ -219,7 +216,7 @@ export function runAPI(express, app, __dirname) { res.status(result.status).json(result.body); } catch { - fail(res, 'ErrorSomethingWentWrong'); + fail(res, "error.api.generic"); } }) diff --git a/api/src/processing/match-action.js b/api/src/processing/match-action.js index 9ad15809..4620d232 100644 --- a/api/src/processing/match-action.js +++ b/api/src/processing/match-action.js @@ -39,7 +39,7 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab switch (action) { default: return createResponse("error", { - code: "ErrorEmptyDownload" + code: "error.api.fetch.empty" }); case "photo": @@ -149,7 +149,7 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab case "audio": if (audioIgnore.includes(host) || (host === "reddit" && r.typeId === "redirect")) { return createResponse("error", { - code: "ErrorEmptyDownload" + code: "error.api.fetch.empty" }) } diff --git a/api/src/processing/match.js b/api/src/processing/match.js index e730b55b..0d60754f 100644 --- a/api/src/processing/match.js +++ b/api/src/processing/match.js @@ -51,12 +51,12 @@ export default async function(host, patternMatch, obj) { if (!testers[host]) { return createResponse("error", { - code: "ErrorUnsupported" + code: "error.api.service.unsupported" }); } if (!(testers[host](patternMatch))) { return createResponse("error", { - code: "ErrorBrokenLink", + code: "error.api.link.invalid", context: { service: host } @@ -230,7 +230,7 @@ export default async function(host, patternMatch, obj) { default: return createResponse("error", { - code: "ErrorUnsupported" + code: "error.api.service.unsupported" }); } @@ -265,7 +265,7 @@ export default async function(host, patternMatch, obj) { }) } catch { return createResponse("error", { - code: "ErrorBadFetch", + code: "error.api.fetch.critical", context: { service: host } diff --git a/api/src/processing/request.js b/api/src/processing/request.js index 85182d60..404821db 100644 --- a/api/src/processing/request.js +++ b/api/src/processing/request.js @@ -10,7 +10,7 @@ export function createResponse(responseType, responseData) { body: { status: "error", error: { - code: code || "Internal Server Error", + code: code || "error.api.fetch.critical", }, critical: true }