class UnauthorizedError {
readonly _tag = 'UnauthorizedError';
}
const fetch = (n: number) =>
Effect.gen(function* ($) {
if (n === 0) {
return yield $(Effect.fail(new UnauthorizedError()));
}
return { data: true };
});
const getSomething = pipe(fetch(0), Effect.orDie);
const result = Effect.runPromise(getSomething).catch((e) => {
/*
I want to catch the UnauthorizedError and throw a redirect at the edge of my app
I can't do this as an Error is thrown, not my UnauthorizedError
*/
if (e instanceof UnauthorizedError) {
throw redirect('/logout');
}
});
class UnauthorizedError {
readonly _tag = 'UnauthorizedError';
}
const fetch = (n: number) =>
Effect.gen(function* ($) {
if (n === 0) {
return yield $(Effect.fail(new UnauthorizedError()));
}
return { data: true };
});
const getSomething = pipe(fetch(0), Effect.orDie);
const result = Effect.runPromise(getSomething).catch((e) => {
/*
I want to catch the UnauthorizedError and throw a redirect at the edge of my app
I can't do this as an Error is thrown, not my UnauthorizedError
*/
if (e instanceof UnauthorizedError) {
throw redirect('/logout');
}
});