From 735b9ab5029f301328c9f9747358038c7d47dadd Mon Sep 17 00:00:00 2001 From: Johann150 Date: Fri, 28 Oct 2022 16:57:56 +0200 Subject: [PATCH] fix some lints --- .../backend/src/server/api/api-handler.ts | 4 +- packages/backend/src/server/api/call.ts | 2 +- packages/backend/src/server/api/error.ts | 12 +- .../src/server/api/openapi/gen-spec.ts | 2 +- .../src/server/api/openapi/http-codes.ts | 132 +++++++++--------- .../backend/src/server/api/openapi/schemas.ts | 2 +- 6 files changed, 78 insertions(+), 76 deletions(-) diff --git a/packages/backend/src/server/api/api-handler.ts b/packages/backend/src/server/api/api-handler.ts index e21585158..30a8dbcf5 100644 --- a/packages/backend/src/server/api/api-handler.ts +++ b/packages/backend/src/server/api/api-handler.ts @@ -25,7 +25,7 @@ export async function handler(endpoint: IEndpoint, ctx: Koa.Context): Promise }, limitActor).catch(e => { + await limiter(limit as IEndpointMeta['limit'] & { key: NonNullable }, limitActor).catch(() => { throw new ApiError('RATE_LIMIT_EXCEEDED'); }); } diff --git a/packages/backend/src/server/api/error.ts b/packages/backend/src/server/api/error.ts index 2cdabce48..b93f5a2d2 100644 --- a/packages/backend/src/server/api/error.ts +++ b/packages/backend/src/server/api/error.ts @@ -8,14 +8,16 @@ export class ApiError extends Error { code: keyof errors = 'INTERNAL_ERROR', info?: any | null, ) { - if(!code in errors) { - info = `Unknown error "${code}" occurred.`; - code = 'INTERNAL_ERROR'; + if (!(code in errors)) { + this.info = `Unknown error "${code}" occurred.`; + this.code = 'INTERNAL_ERROR'; + } else { + this.info = info; + this.code = code; } - const { message, httpStatusCode } = errors[code]; + const { message, httpStatusCode } = errors[this.code]; super(message); - this.code = code; this.message = message; this.httpStatusCode = httpStatusCode; } diff --git a/packages/backend/src/server/api/openapi/gen-spec.ts b/packages/backend/src/server/api/openapi/gen-spec.ts index 497230596..f9795884d 100644 --- a/packages/backend/src/server/api/openapi/gen-spec.ts +++ b/packages/backend/src/server/api/openapi/gen-spec.ts @@ -71,7 +71,7 @@ export function genOpenapiSpec() { const { message, httpStatusCode } = errorDefinitions[code]; const httpCode = httpStatusCode.toString(); - if(!(httpCode in acc)) { + if (!(httpCode in acc)) { acc[httpCode] = { description: httpCodes[httpCode], content: { diff --git a/packages/backend/src/server/api/openapi/http-codes.ts b/packages/backend/src/server/api/openapi/http-codes.ts index 4727ef485..b3b74f867 100644 --- a/packages/backend/src/server/api/openapi/http-codes.ts +++ b/packages/backend/src/server/api/openapi/http-codes.ts @@ -1,67 +1,67 @@ export const httpCodes: Record = { - "100": "Continue", - "101": "Switching Protocols", - "102": "Processing", - "103": "Early Hints", - "200": "OK", - "201": "Created", - "202": "Accepted", - "203": "Non-Authoritative Information", - "204": "No Content", - "205": "Reset Content", - "206": "Partial Content", - "207": "Multi-Status", - "208": "Already Reported", - "226": "IM Used", - "300": "Multiple Choices", - "301": "Moved Permanently", - "302": "Found", - "303": "See Other", - "304": "Not Modified", - "305": "Use Proxy", - "307": "Temporary Redirect", - "308": "Permanent Redirect", - "400": "Bad Request", - "401": "Unauthorized", - "402": "Payment Required", - "403": "Forbidden", - "404": "Not Found", - "405": "Method Not Allowed", - "406": "Not Acceptable", - "407": "Proxy Authentication Required", - "408": "Request Timeout", - "409": "Conflict", - "410": "Gone", - "411": "Length Required", - "412": "Precondition Failed", - "413": "Content Too Large", - "414": "URI Too Long", - "415": "Unsupported Media Type", - "416": "Range Not Satisfiable", - "417": "Expectation Failed", - "418": "I'm a Teapot", - "421": "Misdirected Request", - "422": "Unprocessable Content", - "423": "Locked", - "424": "Failed Dependency", - "425": "Too Early", - "426": "Upgrade Required", - "427": "Unassigned", - "428": "Precondition Required", - "429": "Too Many Requests", - "430": "Unassigned", - "431": "Request Header Fields Too Large", - "451": "Unavailable For Legal Reasons", - "500": "Internal Server Error", - "501": "Not Implemented", - "502": "Bad Gateway", - "503": "Service Unavailable", - "504": "Gateway Timeout", - "505": "HTTP Version Not Supported", - "506": "Variant Also Negotiates", - "507": "Insufficient Storage", - "508": "Loop Detected", - "509": "Unassigned", - "510": "Not Extended", - "511": "Network Authentication Required" -} + '100': 'Continue', + '101': 'Switching Protocols', + '102': 'Processing', + '103': 'Early Hints', + '200': 'OK', + '201': 'Created', + '202': 'Accepted', + '203': 'Non-Authoritative Information', + '204': 'No Content', + '205': 'Reset Content', + '206': 'Partial Content', + '207': 'Multi-Status', + '208': 'Already Reported', + '226': 'IM Used', + '300': 'Multiple Choices', + '301': 'Moved Permanently', + '302': 'Found', + '303': 'See Other', + '304': 'Not Modified', + '305': 'Use Proxy', + '307': 'Temporary Redirect', + '308': 'Permanent Redirect', + '400': 'Bad Request', + '401': 'Unauthorized', + '402': 'Payment Required', + '403': 'Forbidden', + '404': 'Not Found', + '405': 'Method Not Allowed', + '406': 'Not Acceptable', + '407': 'Proxy Authentication Required', + '408': 'Request Timeout', + '409': 'Conflict', + '410': 'Gone', + '411': 'Length Required', + '412': 'Precondition Failed', + '413': 'Content Too Large', + '414': 'URI Too Long', + '415': 'Unsupported Media Type', + '416': 'Range Not Satisfiable', + '417': 'Expectation Failed', + '418': 'I'm a Teapot', + '421': 'Misdirected Request', + '422': 'Unprocessable Content', + '423': 'Locked', + '424': 'Failed Dependency', + '425': 'Too Early', + '426': 'Upgrade Required', + '427': 'Unassigned', + '428': 'Precondition Required', + '429': 'Too Many Requests', + '430': 'Unassigned', + '431': 'Request Header Fields Too Large', + '451': 'Unavailable For Legal Reasons', + '500': 'Internal Server Error', + '501': 'Not Implemented', + '502': 'Bad Gateway', + '503': 'Service Unavailable', + '504': 'Gateway Timeout', + '505': 'HTTP Version Not Supported', + '506': 'Variant Also Negotiates', + '507': 'Insufficient Storage', + '508': 'Loop Detected', + '509': 'Unassigned', + '510': 'Not Extended', + '511': 'Network Authentication Required', +}; diff --git a/packages/backend/src/server/api/openapi/schemas.ts b/packages/backend/src/server/api/openapi/schemas.ts index 4bb72cd8a..04346c53b 100644 --- a/packages/backend/src/server/api/openapi/schemas.ts +++ b/packages/backend/src/server/api/openapi/schemas.ts @@ -48,7 +48,7 @@ export const schemas = { }, info: { description: 'Potentially more information, primarily intended for developers.', - } + }, }, required: ['code', 'endpoint', 'message'], },