UNPKG

abolish

Version:

A javascript object validator.

50 lines (49 loc) 1.18 kB
"use strict"; /** * AbolishError * @class * This class can be used to return custom errors to the validation process */ class AbolishError { constructor(message, data) { this.code = "default"; this.message = message; if (data) this.data = data; return this; } /** * Set code * @param code - A custom error code * @returns {this} - Returns the current instance * @example * new AbolishError("Invalid value").setCode(data); */ setCode(code) { this.code = code; return this; } /** * Set data * @param data - A custom data * @returns {this} - Returns the current instance * @example * new AbolishError("Invalid value").setData(data); */ setData(data) { this.data = data; return this; } /** * Set message * @param message - A custom message * @returns {this} - Returns the current instance * @example * new AbolishError("Invalid value").setMessage(message); */ setMessage(message) { this.message = message; return this; } } module.exports = AbolishError;