Skip to content

Commit

Permalink
feat(serverless): better 500/404 pages (#224)
Browse files Browse the repository at this point in the history
* feat(serverless): better 500/404 pages

* chore: add changeset
  • Loading branch information
QuiiBz authored Nov 1, 2022
1 parent 5e803dc commit 0d2cd1a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-parents-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lagon/serverless': patch
---

Improve 500/400 pages with proper HTML/CSS
19 changes: 19 additions & 0 deletions packages/serverless/public/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://cdn.tailwindcss.com"></script>
<title>404 - Deployment Not Found</title>
</head>

<body>
<section class="w-screen h-screen flex items-center justify-center flex-col">
<h1 class="font-semibold text-3xl text-gray-900 mb-1">Deployment Not Found</h1>
<span class="uppercase text-base text-blue-500 mb-6">404</span>
<p class="text-sm text-gray-800">This Deployment does not exist.</p>
</section>
</body>

</html>
22 changes: 22 additions & 0 deletions packages/serverless/public/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://cdn.tailwindcss.com"></script>
<title>500 - Function Error</title>
</head>

<body>
<section class="w-screen h-screen flex items-center justify-center flex-col">
<h1 class="font-semibold text-3xl text-gray-900 mb-1">Function Error</h1>
<span class="uppercase text-base text-blue-500 mb-6">500</span>
<p class="text-sm text-gray-800">
This Function errored. If you are the owner, <br />
check the "Logs" tab for more information.
</p>
</section>
</body>

</html>
19 changes: 19 additions & 0 deletions packages/serverless/public/502.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://cdn.tailwindcss.com"></script>
<title>502 - Function Resources Reached</title>
</head>

<body>
<section class="w-screen h-screen flex items-center justify-center flex-col">
<h1 class="font-semibold text-3xl text-gray-900 mb-1">Function Resources Reached</h1>
<span class="uppercase text-base text-blue-500 mb-6">502</span>
<p class="text-sm text-gray-800">Resources have been reached for this Function.</p>
</section>
</body>

</html>
15 changes: 10 additions & 5 deletions packages/serverless/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ lazy_static! {
}

const POOL_SIZE: usize = 8;
const PAGE_404: &str = include_str!("../public/404.html");
const PAGE_502: &str = include_str!("../public/502.html");
const PAGE_500: &str = include_str!("../public/500.html");

async fn handle_request(
req: HyperRequest<Body>,
Expand Down Expand Up @@ -224,15 +227,17 @@ async fn handle_request(

Ok(hyper_response)
}
RunResult::Error(error) => Ok(HyperResponse::builder()
RunResult::Timeout | RunResult::MemoryLimit => Ok(HyperResponse::builder()
.status(502)
.body(PAGE_502.into())
.unwrap()),
RunResult::Error(_) => Ok(HyperResponse::builder()
.status(500)
.body(error.into())
.body(PAGE_500.into())
.unwrap()),
RunResult::Timeout => Ok(HyperResponse::new("Timeouted".into())),
RunResult::MemoryLimit => Ok(HyperResponse::new("MemoryLimited".into())),
RunResult::NotFound => Ok(HyperResponse::builder()
.status(404)
.body("Deployment not found".into())
.body(PAGE_404.into())
.unwrap()),
}
}
Expand Down

0 comments on commit 0d2cd1a

Please sign in to comment.