feat: Use asynchandler library for handlers

This commit is contained in:
Joachim Van Herwegen
2024-09-05 11:08:43 +02:00
parent dce39f67e8
commit 58574eec07
186 changed files with 944 additions and 1590 deletions

View File

@@ -1,4 +1,4 @@
import { AsyncHandler } from '../../src/util/handlers/AsyncHandler';
import { AsyncHandler } from 'asynchronous-handlers';
export class StaticAsyncHandler<TOut> extends AsyncHandler<any, TOut> {
private readonly canHandleStatic: boolean;

View File

@@ -105,6 +105,19 @@ export function compareMaps<TKey, TVal>(map1: Map<TKey, TVal>, map2: Map<TKey, T
}
}
/**
* Returns the error thrown by the given function.
* Throws an error if the function does not throw.
*/
export async function getError(fn: () => any): Promise<Error> {
try {
await fn();
} catch (err: unknown) {
return err as Error;
}
throw new Error('Function did not throw');
}
/**
* Mocks (some) functions of the fs system library.
* It is important that you call `jest.mock('node:fs');` in your test file before calling this!!!