New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

discord-error

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord-error

Creates a JavaScript Error from the body response of a Discord API JSON error message

latest
npmnpm
Version
3.0.1
Version published
Maintainers
1
Created
Source

discord-error

Creates a JavaScript Error from the body response of a Discord API JSON error message. It is intended to be used primarily in libraries rather than client code.

Usage

import { DiscordError, isDiscordError } from "discord-error";

// This should be the incoming interaction request
const request = new Request();

// A request to the Discord API that performs some action
const response = await fetch(DISCORD_API, { ...options });

if (!response.ok) {
	const data = await response.json();
	const label = isDiscordError(data) ? data.code : data.error;
	throw new DiscordError(request, response, label, data);
}

Credits

This code is derived from code originally written by the discord.js maintainers in the @discordjs/rest package and distributed under the Apache 2 license. It was changed to be built with Web APIs instead of Node.js APIs.

FAQs

Package last updated on 21 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts