mustom-validator
Version:
Lightweight yet powerful, highly extensible validation/sanitization library
49 lines (40 loc) • 1.2 kB
JavaScript
// MUSTOM, More Than Custom, https://mustom.com
// Copyright © Ryu Woosik. All rights reserved.
class BaseError extends Error {
constructor(code, message, options = {}) {
super(message)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor)
}
this.name = this.constructor.name
this.code = code
this.message = message
if (options.statusCode) {
this.statusCode = options.statusCode
}
if (options.details) {
this.details = options.details
}
if (options.timestamp) {
this.timestamp = options.timestamp
}
}
}
class ValidationError extends BaseError {
constructor(code, message, options = {}) {
super(code, message, options)
this.name = 'ValidationError'
this.statusCode = 422
}
}
class UsageError extends BaseError {
constructor(code, message, options = {}) {
super(code, message, options)
this.name = 'UsageError'
}
}
module.exports = {
BaseError,
ValidationError,
UsageError
}