-
Notifications
You must be signed in to change notification settings - Fork 0
Error
The Err
class is a better way to create errors! It has all the properties of a normal error, and more!
const { Err } = require("shwi-js");
new Err("My leg is missing!", "LEG_CODE", { leg: "missing" });
// All of these properties are optional
The Err(...)
constructor takes in three (all optional) parameters: The error message, The error code, The error object.
The error message is a string that describes the error.
The error code is a breif code of the error, it is also the string logged as [Node/app/Error/<Code>]
in the console.
The error object is just a plain object containing more information about the error, if any. It can also contain the dont_log
boolean value to specify whether to log this error when constructed or not. (true = not logged. false(default) = logged)
The log()
method on an error logs the error to the console.
const { Err } = require("shwi-js");
const error = new Err("Error!", "ERR", { dont_log: true });
error.log();
// Logs the error to the console along with all the details
Make the error fatal. This throws the error to the console, quitting the process.
The as_json
get method returns a JSON object of the error.
The info
get method returns an object with all the error info:
{
id: Number,
code: String,
message: String,
details: {
at: Date,
time: String,
day: String,
timestamp: Number,
localDate: String,
raw_err: Error
},
resolved: Boolean
}
const { Err } = require("shwi-js");
const error = new Err("error", "ERR", {dont_log: true});
const errorInfo = error.info;
The resolve()
method resolves the error. This calls the callback function specified by the user (if any)
The onResolve(Function)
method takes in a function that will be called when the error is resolved.
const shwijs = require("shwi-js");
const error = new shwijs.Err("Error!", "ERR", { dont_log: true });
error.onResolve(() => {
shwijs.Log("Error resolved!");
});
Copyright 2021 @Shwibi
Feel free to open an Issue if you find anything wrong in the module! Or open a new Discussion if you have any suggestions, or just want to give a feedback!
The latest STABLE version is v1.0.0
with the addition of Physics* (depracated from v1.1.0^
).
: v1.1.1
Fixed README
: v1.1.0
Released new Physics
: v0.0.5-beta.2
Released something
: v0.0.5-beta
Released, countdown docs
: v0.0.4
Released
: v0.0.4-alpha.6
fix parser
: v0.0.4-alpha.5
npm update
: v0.0.4-alpha.4
(No additions except documentation edits)
: v0.0.4-alpha.2
Added tank, props, and functions.
: v0.0.4-alpha.1
has nothing new in it, it is just fixation of documentation on npm