Handle any Javascript function as an error and response tuple.
npm install doublet


``shell`
npm i doublet
ts
import axios from 'axios';
import doublet from 'doublet';
import HttpException from 'your-favorite-error-handler';async function fetchUser(id: string): User {
let user;
try {
user = await axios(
/users/${id});
} catch (error) {
throw new HttpException(Could not fetch user ID "${id}", Error; ${error.message}, error.status);
} // Do something with user
}
`$3
`ts
import axios from 'axios';
import doublet from 'doublet';
import HttpException from 'your-favorite-error-handler';async function fetchUser(id: string): User {
const [userError, user] = await doublet(axios,
/users/${id});
if (userError) throw new HttpException(Could not fetch user ID "${id}", Error; ${userError.message}, userError.status); // Do something with user
}
``