Add AccountsAPIError class and productvoucher route
Introduces a custom AccountsAPIError class for consistent error handling and serialization. Adds a new /productvoucher/giftcode route that returns a 404 error response for unimplemented endpoints.
This commit is contained in:
parent
97ae0c43f0
commit
228345c859
32
errors/ServiceError.js
Normal file
32
errors/ServiceError.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
class AccountsAPIError extends Error {
|
||||||
|
constructor(code, path, error, errorMessage) {
|
||||||
|
super(errorMessage || error || "Accounts API Error")
|
||||||
|
this.code = code
|
||||||
|
this.path = path
|
||||||
|
this.errorType = error
|
||||||
|
this.errorMessage = errorMessage
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.errorMessage && this.errorMessage.trim() !== "") {
|
||||||
|
response.errorMessage = this.errorMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = AccountsAPIError
|
||||||
14
routes/minecraftservices/productvoucher.js
Normal file
14
routes/minecraftservices/productvoucher.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
const express = require("express")
|
||||||
|
const router = express.Router()
|
||||||
|
|
||||||
|
router.get("/giftcode", (req, res) => {
|
||||||
|
res.status(404).json({
|
||||||
|
path: "/productvoucher/giftcode",
|
||||||
|
errorType: "NOT_FOUND",
|
||||||
|
error: "NOT_FOUND",
|
||||||
|
errorMessage: "The server has not found anything matching the request URI",
|
||||||
|
developerMessage: "The server has not found anything matching the request URI"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = router
|
||||||
Loading…
x
Reference in New Issue
Block a user