-
Notifications
You must be signed in to change notification settings - Fork 609
fix error pages #5083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix error pages #5083
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| load("@rules_go//go:def.bzl", "go_library") | ||
|
|
||
| go_library( | ||
| name = "errorpage", | ||
| srcs = [ | ||
| "doc.go", | ||
| "errorpage.go", | ||
| "interface.go", | ||
| ], | ||
| embedsrcs = ["error.go.tmpl"], | ||
| importpath = "github.com/unkeyed/unkey/svc/frontline/internal/errorpage", | ||
| visibility = ["//svc/frontline:__subpackages__"], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Package errorpage renders HTML error pages for frontline. | ||
| // | ||
| // Frontline shows error pages for its own errors (routing failures, proxy | ||
| // errors) and for sentinel errors (auth rejections, rate limits). The | ||
| // [Renderer] interface allows swapping the template, e.g. for custom | ||
| // domains with branded error pages. | ||
| // | ||
| // # Template | ||
| // | ||
| // The default implementation embeds error.go.tmpl at compile time and | ||
| // renders it with [html/template]. The template receives a [Data] struct | ||
| // and supports dark/light mode via prefers-color-scheme. | ||
| // | ||
| // # Content Negotiation | ||
| // | ||
| // This package only produces HTML. The caller (frontline middleware or | ||
| // proxy) is responsible for checking the Accept header and falling back | ||
| // to JSON when the client prefers it. | ||
| package errorpage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
| <title>{{.StatusCode}} {{.Title}}</title> | ||
| <style> | ||
| :root { | ||
| --bg: #09090b; | ||
| --fg: #fafafa; | ||
| --muted: #a1a1aa; | ||
| --dim: #71717a; | ||
| --faint: #52525b; | ||
| --border: #27272a; | ||
| --surface: #18181b; | ||
| } | ||
|
|
||
| @media (prefers-color-scheme: light) { | ||
| :root { | ||
| --bg: #fafafa; | ||
| --fg: #09090b; | ||
| --muted: #71717a; | ||
| --dim: #a1a1aa; | ||
| --faint: #a1a1aa; | ||
| --border: #e4e4e7; | ||
| --surface: #f4f4f5; | ||
| } | ||
| } | ||
|
|
||
| *, *::before, *::after { | ||
| margin: 0; | ||
| padding: 0; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| body { | ||
| font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", "Liberation Mono", Menlo, Monaco, Consolas, monospace; | ||
| min-height: 100vh; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| padding: 2rem; | ||
| background: var(--bg); | ||
| color: var(--fg); | ||
| -webkit-font-smoothing: antialiased; | ||
| } | ||
|
|
||
| .container { | ||
| max-width: 480px; | ||
| width: 100%; | ||
| } | ||
|
|
||
| .header { | ||
| display: flex; | ||
| align-items: baseline; | ||
| gap: 0.75rem; | ||
| } | ||
|
|
||
| .status { | ||
| font-size: 3rem; | ||
| font-weight: 700; | ||
| line-height: 1; | ||
| letter-spacing: -0.03em; | ||
| } | ||
|
|
||
| .title { | ||
| font-size: 1rem; | ||
| font-weight: 400; | ||
| color: var(--muted); | ||
| } | ||
|
|
||
| .message { | ||
| margin-top: 1.25rem; | ||
| padding: 1rem 1.25rem; | ||
| font-size: 0.8125rem; | ||
| line-height: 1.7; | ||
| color: var(--muted); | ||
| background: var(--surface); | ||
| border: 1px solid var(--border); | ||
| border-radius: 6px; | ||
| } | ||
|
|
||
| .meta { | ||
| margin-top: 1.25rem; | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 0.375rem; | ||
| font-size: 0.75rem; | ||
| } | ||
|
|
||
| .meta-row { | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| padding: 0.25rem 0; | ||
| } | ||
|
|
||
| .meta-label { | ||
| color: var(--faint); | ||
| text-transform: uppercase; | ||
| font-size: 0.6875rem; | ||
| letter-spacing: 0.05em; | ||
| } | ||
|
|
||
| .meta-value { | ||
| color: var(--muted); | ||
| } | ||
|
|
||
| .meta-value a { | ||
| color: var(--muted); | ||
| text-decoration: underline; | ||
| text-decoration-color: var(--faint); | ||
| text-underline-offset: 3px; | ||
| transition: color 0.15s, text-decoration-color 0.15s; | ||
| } | ||
|
|
||
| .meta-value a:hover { | ||
| color: var(--fg); | ||
| text-decoration-color: var(--fg); | ||
| } | ||
|
|
||
| .footer { | ||
| margin-top: 2rem; | ||
| padding-top: 1rem; | ||
| border-top: 1px solid var(--border); | ||
| font-size: 0.6875rem; | ||
| color: var(--faint); | ||
| } | ||
|
|
||
| .footer a { | ||
| color: var(--dim); | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| .footer a:hover { | ||
| color: var(--fg); | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div class="container"> | ||
| <div class="header"> | ||
| <div class="status">{{.StatusCode}}</div> | ||
| <div class="title">{{.Title}}</div> | ||
| </div> | ||
|
|
||
| <div class="message">{{.Message}}</div> | ||
|
|
||
| <div class="meta"> | ||
| {{if .RequestID}} | ||
| <div class="meta-row"> | ||
| <span class="meta-label">Request ID</span> | ||
| <span class="meta-value">{{.RequestID}}</span> | ||
| </div> | ||
| {{end}} | ||
| {{if .ErrorCode}} | ||
| <div class="meta-row"> | ||
| <span class="meta-label">Code</span> | ||
| <span class="meta-value">{{if .DocsURL}}<a href="{{.DocsURL}}" target="_blank">{{.ErrorCode}}</a>{{else}}{{.ErrorCode}}{{end}}</span> | ||
| </div> | ||
| {{end}} | ||
| </div> | ||
|
|
||
| <div class="footer"> | ||
| Need help? <a href="mailto:support@unkey.com">support@unkey.com</a> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package errorpage | ||
|
|
||
| import ( | ||
| "bytes" | ||
| _ "embed" | ||
| "html/template" | ||
| ) | ||
|
|
||
| //go:embed error.go.tmpl | ||
| var defaultTemplate string | ||
|
|
||
| // defaultRenderer uses the embedded HTML template. | ||
| type defaultRenderer struct { | ||
| tmpl *template.Template | ||
| } | ||
|
|
||
| func (r *defaultRenderer) Render(data Data) ([]byte, error) { | ||
| var buf bytes.Buffer | ||
| if err := r.tmpl.Execute(&buf, data); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return buf.Bytes(), nil | ||
| } | ||
|
|
||
| // NewRenderer returns a [Renderer] that uses the default embedded error page template. | ||
| // Panics if the template fails to parse (should never happen with an embedded template). | ||
| func NewRenderer() Renderer { | ||
| return &defaultRenderer{ | ||
| tmpl: template.Must(template.New("error").Parse(defaultTemplate)), | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package errorpage | ||
|
|
||
| // Data contains all the fields available to the error page template. | ||
| type Data struct { | ||
| // StatusCode is the HTTP status code (e.g. 401, 502). | ||
| StatusCode int | ||
|
|
||
| // Title is the human-readable status text (e.g. "Unauthorized"). | ||
| Title string | ||
|
|
||
| // Message is a longer explanation shown to the user. | ||
| Message string | ||
|
|
||
| // ErrorCode is the URN-style error code (e.g. "err:sentinel:unauthorized:invalid_key"). | ||
| ErrorCode string | ||
|
|
||
| // DocsURL links to documentation for this error code. Empty if unavailable. | ||
| DocsURL string | ||
|
|
||
| // RequestID is the frontline request ID for support reference. | ||
| RequestID string | ||
| } | ||
|
|
||
| // Renderer renders an HTML error page from [Data]. | ||
| type Renderer interface { | ||
| Render(data Data) ([]byte, error) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.