next-expose
Version:
A fluent, type-safe API routing and middleware layer for the Next.js App Router.
71 lines (70 loc) • 1.81 kB
JavaScript
class t extends Error {
/** The HTTP status code appropriate for this error. */
statusCode;
/** An optional payload containing structured error details (e.g., field validation errors). */
payload;
/**
* Constructs an ApiError instance.
* @param {number} statusCode - The HTTP status code.
* @param {string} message - A user-friendly error message.
* @param {ErrorPayload} [payload=null] - Optional structured data about the error.
*/
constructor(r, o, s = null) {
super(o), this.statusCode = r, this.payload = s, Object.setPrototypeOf(this, new.target.prototype);
}
}
function n(e) {
return e instanceof t;
}
class c extends t {
constructor(r, o = "Validation failed") {
super(400, o, r);
}
}
class u extends t {
constructor(r = "The request could not be understood or processed.") {
super(400, r);
}
}
class a extends t {
constructor(r = "Authentication is required for this resource.") {
super(401, r);
}
}
class i extends t {
constructor(r = "You are not authorized to perform this action.") {
super(403, r);
}
}
class d extends t {
constructor(r = "The requested resource was not found.") {
super(404, r);
}
}
class l extends t {
constructor(r = "A conflict occurred with the current state of the resource.") {
super(409, r);
}
}
class p extends t {
constructor(r = "Too many requests, please try again later.", o = null) {
super(429, r, o);
}
}
class h extends t {
constructor(r = "An unexpected internal server error occurred.") {
super(500, r);
}
}
export {
t as ApiError,
a as AuthenticationError,
i as AuthorizationError,
u as BadRequestError,
l as ConflictError,
h as InternalServerError,
d as NotFoundError,
p as TooManyRequestsError,
c as ValidationError,
n as isApiError
};