Add base project files including environment example, license, README, .gitignore, error classes, ESLint config, database modules, texture assets, repositories, routes, schemas, services, and server entry point. This establishes the foundational structure for a Yggdrasil-compatible REST API with modular error handling, database setup, and route organization.
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
class ServiceError extends Error {
|
|
constructor(code, path, error, errorMessage, details = null) {
|
|
super(errorMessage || error || "Accounts API Error")
|
|
this.code = code
|
|
this.path = path
|
|
this.errorType = error
|
|
this.errorMessage = errorMessage
|
|
this.developerMessage = errorMessage
|
|
this.details = details
|
|
this.isOperational = true
|
|
|
|
Error.captureStackTrace(this, this.constructor)
|
|
}
|
|
|
|
serialize() {
|
|
const response = {}
|
|
|
|
if (this.path && this.path.trim() !== "") {
|
|
response.path = this.path.replace(/:(\w+)/g, "<$1>")
|
|
}
|
|
|
|
if (this.errorType && this.errorType.trim() !== "") {
|
|
response.error = this.errorType
|
|
response.errorType = this.errorType
|
|
}
|
|
|
|
if (this.details) {
|
|
response.details = this.details
|
|
}
|
|
|
|
if (this.errorMessage && this.errorMessage.trim() !== "") {
|
|
response.errorMessage = this.errorMessage
|
|
}
|
|
|
|
if (this.developerMessage && this.developerMessage.trim() !== "") {
|
|
response.developerMessage = this.developerMessage
|
|
}
|
|
|
|
return response
|
|
}
|
|
}
|
|
|
|
module.exports = ServiceError |