Skip to content

Commit

Permalink
feat(tasks): raises can take a string as an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Feb 19, 2021
1 parent df08e29 commit f0dbd5a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/tasks/process/raises.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Task, Context } from '../../definitions';
import { UnaryFn } from 'type-core';

export function raises(error: Error | UnaryFn<Context, Error>): Task.Sync {
export function raises(
error: Error | string | UnaryFn<Context, Error | string>
): Task.Sync {
return (ctx: Context): void => {
throw typeof error === 'function' ? error(ctx) : error;
const err = typeof error === 'function' ? error(ctx) : error;
throw typeof err === 'string' ? Error(err) : err;
};
}

0 comments on commit f0dbd5a

Please sign in to comment.