Skip to content

Commit a221d81

Browse files
committed
change: Extend actionFunction to allow to defined the error type
1 parent 6dbaddd commit a221d81

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/web/entity/hooks/actionFunction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import {isDefined} from 'gmp/utils/identity';
1919
* @throws {*} - The error from the rejected promise if onError callback is not provided.
2020
*/
2121

22-
const actionFunction = async <ResponseType, ReturnType>(
22+
const actionFunction = async <ResponseType, ReturnType, ErrorType = unknown>(
2323
promise: Promise<ResponseType>,
2424
onSuccess?: (response: ResponseType) => ReturnType,
25-
onError?: (error: unknown) => ReturnType,
25+
onError?: (error: ErrorType) => ReturnType,
2626
successMessage?: string,
2727
): Promise<ReturnType | ResponseType> => {
2828
try {
@@ -36,7 +36,7 @@ const actionFunction = async <ResponseType, ReturnType>(
3636
return response;
3737
} catch (error) {
3838
if (isDefined(onError)) {
39-
return onError(error);
39+
return onError(error as ErrorType);
4040
}
4141
throw error;
4242
}

0 commit comments

Comments
 (0)