srctree

Jeremy Hertel parent e80300aa 7354c4ae aa80bdfb
Merge branch 'error-pages'

src/fallback_html/4XX.html added: 47, removed: 13, total 34
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Verse: Not Found</title>
<title>404: Not Found</title>
<style>
html {
color-scheme: light dark;
@@ -15,7 +15,7 @@
</style>
</head>
<body>
<h1>404: Task Failed Successfully!</h1>
<h1>404: Wrong Castle</h1>
<p>The page you're looking for is in another castle :(<br/>
Please try again repeatedly... surely it'll work this time!</p>
<p>If you are the system administrator you should already know why <br/>
 
filename was Deleted added: 47, removed: 13, total 34
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>405: Method Not Allowed</title>
<style>
html {
color-scheme: light dark;
min-height: 100%;
}
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>405: Respectful Communication</h1>
<p>The server didn't like how you communicated with it<br />
Try again with a more appropiate verb.</p>
<p><em>Sincerely, Karen from Human Resources.</em></p>
</body>
</html>
 
 
src/fallback_html/5XX.html added: 47, removed: 13, total 34
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Verse: Internal Server Error</title>
<title>500: Internal Server Error</title>
<style>
html {
color-scheme: light dark;
@@ -14,7 +14,7 @@
</style>
</head>
<body>
<h1>Task Failed Successfully!</h1>
<h1>500: Task Failed Successfully!</h1>
<p>The server started working on your request, but then it died. Which is
really weird, because it was so full of life just the other day!</p>
<p> This crash wasn't your fault... but I'm still probably gonna blame you.
 
src/router.zig added: 47, removed: 13, total 34
@@ -173,16 +173,23 @@ pub fn defaultResponse(comptime code: std.http.Status) BuildFn {
 
fn notFound(vrs: *Verse) Error!void {
vrs.status = .not_found;
const E4XX = @embedFile("fallback_html/4XX.html");
const E404 = @embedFile("fallback_html/404.html");
try vrs.quickStart();
return vrs.sendRawSlice(E4XX);
return vrs.sendRawSlice(E404);
}
 
fn internalServerError(vrs: *Verse) Error!void {
vrs.status = .internal_server_error;
const E5XX = @embedFile("fallback_html/5XX.html");
const E500 = @embedFile("fallback_html/500.html");
try vrs.quickStart();
return vrs.sendRawSlice(E5XX);
return vrs.sendRawSlice(E500);
}
 
fn methodNotAllowed(vrs: *Verse) Error!void {
vrs.status = .method_not_allowed;
const E405 = @embedFile("fallback_html/405.html");
try vrs.quickStart();
return vrs.sendRawSlice(E405);
}
 
fn default(vrs: *Verse) Error!void {
@@ -205,8 +212,11 @@ pub fn router(vrs: *Verse, comptime routes: []const Match) Error!BuildFn {
if (eql(u8, search, ep.name)) {
switch (ep.match) {
.build => |call| {
if (ep.methods.matchMethod(vrs.request.method))
if (ep.methods.matchMethod(vrs.request.method)) {
return call;
} else {
return methodNotAllowed;
}
},
.route => |route| {
return route(vrs) catch |err| switch (err) {