Add session join schema and enhance error serialization
Introduces a Zod schema for the Minecraft session join endpoint, validating accessToken, selectedProfile, and serverId. Updates ValidationError to support serialization via YggdrasilError and SessionError for improved error formatting.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const path = require("node:path")
|
||||
const DefaultError = require("./DefaultError")
|
||||
const YggdrasilError = require("./YggdrasilError")
|
||||
const SessionError = require("./SessionError")
|
||||
const logger = require("../modules/logger")
|
||||
|
||||
class ValidationError extends DefaultError {
|
||||
@@ -34,11 +35,23 @@ class ValidationError extends DefaultError {
|
||||
|
||||
serialize() {
|
||||
if (this.config.errorFormat === "YggdrasilError") {
|
||||
return {
|
||||
error: this.config.errorName || "IllegalArgumentException",
|
||||
errorMessage: this.message,
|
||||
cause: JSON.stringify(this.formattedErrors)
|
||||
}
|
||||
const err = new YggdrasilError(
|
||||
this.code,
|
||||
this.config.errorName || "IllegalArgumentException",
|
||||
this.message,
|
||||
JSON.stringify(this.formattedErrors)
|
||||
)
|
||||
return err.serialize()
|
||||
}
|
||||
|
||||
if (this.config.errorFormat === "SessionError") {
|
||||
const err = new SessionError(
|
||||
this.code,
|
||||
this.config.errorName || "Forbidden",
|
||||
this.message,
|
||||
this.context.path || ""
|
||||
)
|
||||
return err.serialize()
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user