mirror of
https://github.com/Xevion/xevion.dev.git
synced 2026-01-31 14:26:37 -06:00
feat: add prerendered error pages with Rust integration
- Prerender 20+ HTTP error codes (4xx/5xx) at build time - Embed error pages in binary and serve via Axum - Intercept error responses for HTML requests - Add transient flag for retry-worthy errors (502/503/504)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Single source of truth for all HTTP error codes.
|
||||
* Used by:
|
||||
* - SvelteKit EntryGenerator (prerendering)
|
||||
* - Error page components (rendering)
|
||||
* - Rust assets.rs (validation only)
|
||||
*/
|
||||
export const ERROR_CODES = {
|
||||
// 4xx Client Errors
|
||||
400: { message: "Bad request", transient: false },
|
||||
401: { message: "Unauthorized", transient: false },
|
||||
403: { message: "Forbidden", transient: false },
|
||||
404: { message: "Page not found", transient: false },
|
||||
405: { message: "Method not allowed", transient: false },
|
||||
406: { message: "Not acceptable", transient: false },
|
||||
408: { message: "Request timeout", transient: true },
|
||||
409: { message: "Conflict", transient: false },
|
||||
410: { message: "Gone", transient: false },
|
||||
413: { message: "Payload too large", transient: false },
|
||||
414: { message: "URI too long", transient: false },
|
||||
415: { message: "Unsupported media type", transient: false },
|
||||
418: { message: "I'm a teapot", transient: false }, // RFC 2324 Easter egg
|
||||
422: { message: "Unprocessable entity", transient: false },
|
||||
429: { message: "Too many requests", transient: true },
|
||||
451: { message: "Unavailable for legal reasons", transient: false },
|
||||
|
||||
// 5xx Server Errors
|
||||
500: { message: "Internal server error", transient: false },
|
||||
501: { message: "Not implemented", transient: false },
|
||||
502: { message: "Bad gateway", transient: true },
|
||||
503: { message: "Service unavailable", transient: true },
|
||||
504: { message: "Gateway timeout", transient: true },
|
||||
505: { message: "HTTP version not supported", transient: false },
|
||||
} as const;
|
||||
|
||||
export type ErrorCode = keyof typeof ERROR_CODES;
|
||||
|
||||
// Helper to check if error code is defined
|
||||
export function isDefinedErrorCode(code: number): code is ErrorCode {
|
||||
return code in ERROR_CODES;
|
||||
}
|
||||
+13
-12
@@ -16,18 +16,19 @@ export type OGImageSpec =
|
||||
* @returns Full URL to the R2-hosted image
|
||||
*/
|
||||
export function getOGImageUrl(spec: OGImageSpec): string {
|
||||
const R2_BASE = import.meta.env.VITE_OG_R2_BASE_URL;
|
||||
const R2_BASE = import.meta.env.VITE_OG_R2_BASE_URL;
|
||||
|
||||
if (!R2_BASE) {
|
||||
throw new Error("VITE_OG_R2_BASE_URL environment variable is not set");
|
||||
}
|
||||
if (!R2_BASE) {
|
||||
// During prerendering or development, use a fallback placeholder
|
||||
return "/og/placeholder.png";
|
||||
}
|
||||
|
||||
switch (spec.type) {
|
||||
case "index":
|
||||
return `${R2_BASE}/og/index.png`;
|
||||
case "projects":
|
||||
return `${R2_BASE}/og/projects.png`;
|
||||
case "project":
|
||||
return `${R2_BASE}/og/project/${spec.id}.png`;
|
||||
}
|
||||
switch (spec.type) {
|
||||
case "index":
|
||||
return `${R2_BASE}/og/index.png`;
|
||||
case "projects":
|
||||
return `${R2_BASE}/og/projects.png`;
|
||||
case "project":
|
||||
return `${R2_BASE}/og/project/${spec.id}.png`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user