Package Exports
- fuuu
Readme
fuu
Don’t lose your mind, safely execute functions.
Installation
You can install this package using npm:
npm install fuuu
Usage
import * as f from "fuuu"
interface People {
name: string
height: string
mass: string
gender: string
}
const getVaderDetails = async () => {
const response = await fetch("https://swapi.dev/api/people/4/")
return response.json() as Promise<People>
}
const main = async () => {
const vader = await f.safe(getVaderDetails)
if (vader.error) {
// error handling
return
}
console.log(vader.data)
}
Retries
const vader = await f.safe(getVaderDetails, {
retries: 3,
retryDelay: 1000,
})
Timeout
const vader = await f.safe(getVaderDetails, {
timeout: 3000,
})
const isTimeoutError = vader.error instanceof f.TimeoutError