Doublet
Handle any Javascript function as an error and response tuple.
Install / Use
/learn @mats852/DoubletREADME
doublet
Handle any Javascript and Typescript function as an error and response tuple. This prevents declaring variables outside of a try/catch block for a cleaner flow.
Installation
npm i doublet
Usage
Traditionnal error handling
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
}
With doublet
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
}
Related Skills
node-connect
341.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
341.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.6kCommit, push, and open a PR
