Skip to content

Create neat, nicely formatted errors for websocket clients

License

Notifications You must be signed in to change notification settings

CactusDev/ws-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ws-error

Create neat, nicely formatted errors for your websocket clients.

Example

import * as WSErr from "ws-error";

// Create an error to play around with
const error = WSErr.invalidData();

// Some attributes can be set after the fact.
// Errors can optionally have error codes
error.code(123);

// Errors can also have custom meta set after the fact.
error.extra({
	stuff: "things"
});

// These calls are chainable too
error.code(123).extra({stuff: "things"});

// Finally, you can turn this into JSON, or a string.
console.log(error.json());
console.log(error.string());

// All errors have default messages that go along with them, but you can override these.
const otherError = WSError.badLogin("learn2login");

Error Types

Invalid Login badLogin (Bad login information from the client)

Invalid Data invalidData (Bad data sent by the client)

Closing closing (Indicates the server is closing)

About

Create neat, nicely formatted errors for websocket clients

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published