fix some lints

This commit is contained in:
Johann150 2022-10-28 16:57:56 +02:00
parent fb76843c19
commit 735b9ab502
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
6 changed files with 78 additions and 76 deletions

View file

@ -25,7 +25,7 @@ export async function handler(endpoint: IEndpoint, ctx: Koa.Context): Promise<vo
endpoint: endpoint.name, endpoint: endpoint.name,
}, },
}; };
} };
// Authentication // Authentication
// for GET requests, do not even pass on the body parameter as it is considered unsafe // for GET requests, do not even pass on the body parameter as it is considered unsafe
@ -52,4 +52,4 @@ export async function handler(endpoint: IEndpoint, ctx: Koa.Context): Promise<vo
error(new ApiError()); error(new ApiError());
} }
}); });
}; }

View file

@ -36,7 +36,7 @@ export default async (endpoint: string, user: CacheableLocalUser | null | undefi
} }
// Rate limit // Rate limit
await limiter(limit as IEndpointMeta['limit'] & { key: NonNullable<string> }, limitActor).catch(e => { await limiter(limit as IEndpointMeta['limit'] & { key: NonNullable<string> }, limitActor).catch(() => {
throw new ApiError('RATE_LIMIT_EXCEEDED'); throw new ApiError('RATE_LIMIT_EXCEEDED');
}); });
} }

View file

@ -8,14 +8,16 @@ export class ApiError extends Error {
code: keyof errors = 'INTERNAL_ERROR', code: keyof errors = 'INTERNAL_ERROR',
info?: any | null, info?: any | null,
) { ) {
if(!code in errors) { if (!(code in errors)) {
info = `Unknown error "${code}" occurred.`; this.info = `Unknown error "${code}" occurred.`;
code = 'INTERNAL_ERROR'; this.code = 'INTERNAL_ERROR';
} else {
this.info = info;
this.code = code;
} }
const { message, httpStatusCode } = errors[code]; const { message, httpStatusCode } = errors[this.code];
super(message); super(message);
this.code = code;
this.message = message; this.message = message;
this.httpStatusCode = httpStatusCode; this.httpStatusCode = httpStatusCode;
} }

View file

@ -71,7 +71,7 @@ export function genOpenapiSpec() {
const { message, httpStatusCode } = errorDefinitions[code]; const { message, httpStatusCode } = errorDefinitions[code];
const httpCode = httpStatusCode.toString(); const httpCode = httpStatusCode.toString();
if(!(httpCode in acc)) { if (!(httpCode in acc)) {
acc[httpCode] = { acc[httpCode] = {
description: httpCodes[httpCode], description: httpCodes[httpCode],
content: { content: {

View file

@ -1,67 +1,67 @@
export const httpCodes: Record<string, string> = { export const httpCodes: Record<string, string> = {
"100": "Continue", '100': 'Continue',
"101": "Switching Protocols", '101': 'Switching Protocols',
"102": "Processing", '102': 'Processing',
"103": "Early Hints", '103': 'Early Hints',
"200": "OK", '200': 'OK',
"201": "Created", '201': 'Created',
"202": "Accepted", '202': 'Accepted',
"203": "Non-Authoritative Information", '203': 'Non-Authoritative Information',
"204": "No Content", '204': 'No Content',
"205": "Reset Content", '205': 'Reset Content',
"206": "Partial Content", '206': 'Partial Content',
"207": "Multi-Status", '207': 'Multi-Status',
"208": "Already Reported", '208': 'Already Reported',
"226": "IM Used", '226': 'IM Used',
"300": "Multiple Choices", '300': 'Multiple Choices',
"301": "Moved Permanently", '301': 'Moved Permanently',
"302": "Found", '302': 'Found',
"303": "See Other", '303': 'See Other',
"304": "Not Modified", '304': 'Not Modified',
"305": "Use Proxy", '305': 'Use Proxy',
"307": "Temporary Redirect", '307': 'Temporary Redirect',
"308": "Permanent Redirect", '308': 'Permanent Redirect',
"400": "Bad Request", '400': 'Bad Request',
"401": "Unauthorized", '401': 'Unauthorized',
"402": "Payment Required", '402': 'Payment Required',
"403": "Forbidden", '403': 'Forbidden',
"404": "Not Found", '404': 'Not Found',
"405": "Method Not Allowed", '405': 'Method Not Allowed',
"406": "Not Acceptable", '406': 'Not Acceptable',
"407": "Proxy Authentication Required", '407': 'Proxy Authentication Required',
"408": "Request Timeout", '408': 'Request Timeout',
"409": "Conflict", '409': 'Conflict',
"410": "Gone", '410': 'Gone',
"411": "Length Required", '411': 'Length Required',
"412": "Precondition Failed", '412': 'Precondition Failed',
"413": "Content Too Large", '413': 'Content Too Large',
"414": "URI Too Long", '414': 'URI Too Long',
"415": "Unsupported Media Type", '415': 'Unsupported Media Type',
"416": "Range Not Satisfiable", '416': 'Range Not Satisfiable',
"417": "Expectation Failed", '417': 'Expectation Failed',
"418": "I'm a Teapot", '418': 'I'm a Teapot',
"421": "Misdirected Request", '421': 'Misdirected Request',
"422": "Unprocessable Content", '422': 'Unprocessable Content',
"423": "Locked", '423': 'Locked',
"424": "Failed Dependency", '424': 'Failed Dependency',
"425": "Too Early", '425': 'Too Early',
"426": "Upgrade Required", '426': 'Upgrade Required',
"427": "Unassigned", '427': 'Unassigned',
"428": "Precondition Required", '428': 'Precondition Required',
"429": "Too Many Requests", '429': 'Too Many Requests',
"430": "Unassigned", '430': 'Unassigned',
"431": "Request Header Fields Too Large", '431': 'Request Header Fields Too Large',
"451": "Unavailable For Legal Reasons", '451': 'Unavailable For Legal Reasons',
"500": "Internal Server Error", '500': 'Internal Server Error',
"501": "Not Implemented", '501': 'Not Implemented',
"502": "Bad Gateway", '502': 'Bad Gateway',
"503": "Service Unavailable", '503': 'Service Unavailable',
"504": "Gateway Timeout", '504': 'Gateway Timeout',
"505": "HTTP Version Not Supported", '505': 'HTTP Version Not Supported',
"506": "Variant Also Negotiates", '506': 'Variant Also Negotiates',
"507": "Insufficient Storage", '507': 'Insufficient Storage',
"508": "Loop Detected", '508': 'Loop Detected',
"509": "Unassigned", '509': 'Unassigned',
"510": "Not Extended", '510': 'Not Extended',
"511": "Network Authentication Required" '511': 'Network Authentication Required',
} };

View file

@ -48,7 +48,7 @@ export const schemas = {
}, },
info: { info: {
description: 'Potentially more information, primarily intended for developers.', description: 'Potentially more information, primarily intended for developers.',
} },
}, },
required: ['code', 'endpoint', 'message'], required: ['code', 'endpoint', 'message'],
}, },