diff --git a/src/index.test.ts b/src/index.test.ts index bddba41..c8203e4 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -138,5 +138,5 @@ test('fold unknown', () => { successMock, ); - expect(() => view(otherMock)).toThrowError('Unknown RemoteData type used'); + expect(() => view(otherMock)).toThrowError('Unknown RemoteData state:'); }); diff --git a/src/index.ts b/src/index.ts index 4e350c2..a311716 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,7 +20,7 @@ export class Failure { constructor(public error: E) { if (error === null || error === undefined) { - fail('Parameter "error" is required'); + throw new Error('Parameter "error" is required'); } } } @@ -30,7 +30,7 @@ export class Success { constructor(public data: D) { if (data === null || data === undefined) { - fail('Parameter "data" is required'); + throw new Error('Parameter "data" is required'); } } } @@ -52,11 +52,13 @@ export function fold( case Kinds.Success: return success(state.data); default: - return fail('Unknown RemoteData type used'); + throw new NeverError(state); } } } -function fail(error: string): never { - throw new Error(error); +class NeverError extends Error { + constructor(value: never) { + super(`Unknown RemoteData state: ${value}`); + } }