Skip to content

Instantly share code, notes, and snippets.

View gentax's full-sized avatar

Paolo 'gentax' Genta gentax

View GitHub Profile
@gentax
gentax / tryCatch.ts
Created February 24, 2025 09:07
Instead of repeating try/catch code in every async requests, we can use a dedicated function
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};