Fix usages of explicit any
This commit is contained in:
parent
4a09d2e1fe
commit
404a2ecb16
@ -23,9 +23,9 @@ export default abstract class FileUploadMiddleware extends Middleware {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
const bag = new ValidationBag();
|
||||
const fileError = new FileError(e);
|
||||
const fileError = new FileError(String(e));
|
||||
fileError.thingName = this.getDefaultField();
|
||||
bag.addMessage(fileError);
|
||||
next(bag);
|
||||
|
23
src/Utils.ts
23
src/Utils.ts
@ -1,4 +1,4 @@
|
||||
import {promises as fs} from "fs";
|
||||
import fs, {promises as afs} from "fs";
|
||||
import path from "path";
|
||||
|
||||
export async function sleep(ms: number): Promise<void> {
|
||||
@ -49,10 +49,10 @@ export function getMethods<T extends { [p: string]: unknown }>(obj: T): string[]
|
||||
}
|
||||
|
||||
export async function listFilesRecursively(dir: string): Promise<string[]> {
|
||||
const localFiles = await fs.readdir(dir);
|
||||
const localFiles = await afs.readdir(dir);
|
||||
const files: string[] = [];
|
||||
for (const file of localFiles.map(file => path.join(dir, file))) {
|
||||
const stat = await fs.stat(file);
|
||||
const stat = await afs.stat(file);
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
files.push(...await listFilesRecursively(file));
|
||||
@ -65,14 +65,17 @@ export async function listFilesRecursively(dir: string): Promise<string[]> {
|
||||
|
||||
|
||||
export async function doesFileExist(file: string): Promise<boolean> {
|
||||
try {
|
||||
await fs.stat(file);
|
||||
} catch (err: any) {
|
||||
if (err?.code === 'ENOENT') {
|
||||
return false;
|
||||
return await new Promise<boolean>((resolve, reject) => {
|
||||
fs.stat(file, err => {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
return resolve(false);
|
||||
} else {
|
||||
throw err;
|
||||
return reject(err);
|
||||
}
|
||||
} else {
|
||||
return resolve(true);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -48,8 +48,12 @@ export default class MailComponent extends ApplicationComponent {
|
||||
try {
|
||||
await util.promisify(transporter.verify)();
|
||||
this.transporter = transporter;
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
throw new MailError('Connection to mail service unsuccessful.', e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
logger.info(`Mail ready to be distributed via ${config.get('mail.host')}:${config.get('mail.port')}`);
|
||||
|
@ -183,9 +183,14 @@ export default class MysqlConnectionManager {
|
||||
try {
|
||||
const result = await query('SELECT id FROM migrations ORDER BY id DESC LIMIT 1');
|
||||
currentVersion = Number(result.results[0]?.id);
|
||||
} catch (e: any) {
|
||||
if (e.code === 'ECONNREFUSED' || e.code !== 'ER_NO_SUCH_TABLE') {
|
||||
throw new Error('Cannot run migrations: ' + e.code);
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
const mysqlError = e as MysqlError;
|
||||
if (mysqlError.code !== 'ER_NO_SUCH_TABLE') {
|
||||
throw new Error('Cannot run migrations: ' + mysqlError.code);
|
||||
}
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,8 +61,12 @@ export default class Validator<V> {
|
||||
if (result instanceof Promise) {
|
||||
result = await result;
|
||||
}
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
throw new ServerError(`An error occurred while validating ${thingName} with value "${value}".`, e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
if (result === false && step.throw) {
|
||||
|
@ -1,3 +1,5 @@
|
||||
import {MysqlError} from "mysql";
|
||||
|
||||
import Migration from "../db/Migration.js";
|
||||
import {query} from "../db/MysqlConnectionManager.js";
|
||||
|
||||
@ -8,8 +10,8 @@ export default class CreateMigrationsTable extends Migration {
|
||||
public async shouldRun(currentVersion: number): Promise<boolean> {
|
||||
try {
|
||||
await query('SELECT 1 FROM migrations LIMIT 1');
|
||||
} catch (e: any) {
|
||||
if (e.code !== 'ER_NO_SUCH_TABLE') {
|
||||
} catch (e) {
|
||||
if (!(e instanceof Error) || (e as MysqlError).code !== 'ER_NO_SUCH_TABLE') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user