SkillAgentSearch skills...

Doublet

Handle any Javascript function as an error and response tuple.

Install / Use

/learn @mats852/Doublet
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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.

doublet Github licence CI

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

View on GitHub
GitHub Stars27
CategoryDevelopment
Updated1y ago
Forks0

Languages

TypeScript

Security Score

75/100

Audited on Dec 23, 2024

No findings