3.0.1 • Published 1 year ago

discord-error v3.0.1

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
1 year ago

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.

3.0.1

1 year ago

3.0.0

1 year ago

2.0.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

1.3.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago