Skip to content

Commit b8fb930

Browse files
authored
Merge pull request #69 from everywall/errorpage
Render error page when accept header is text/html
2 parents 0940bbb + ee26eaf commit b8fb930

File tree

10 files changed

+473
-148
lines changed

10 files changed

+473
-148
lines changed

.github/workflows/build-css.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Build Tailwind CSS
33
on:
44
push:
55
paths:
6+
- "handlers/error_page.html"
67
- "handlers/form.html"
78
- "handlers/playground.html"
89
- "proxychain/responsemodifiers/vendor/generate_readable_outline.html"

cmd/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func main() {
139139

140140
app.Use(handlers.Auth())
141141
app.Use(handlers.Favicon())
142+
app.Use(handlers.RenderErrorPage())
142143

143144
if os.Getenv("NOLOGS") != "true" {
144145
app.Use(func(c *fiber.Ctx) error {

handlers/api_modifiers_structdef.gen.go

+65-65
Large diffs are not rendered by default.

handlers/error_page.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package handlers
2+
3+
import (
4+
"embed"
5+
"fmt"
6+
"html/template"
7+
"strings"
8+
9+
"github.com/gofiber/fiber/v2"
10+
)
11+
12+
//go:embed error_page.html
13+
var errorHTML embed.FS
14+
15+
func RenderErrorPage() fiber.Handler {
16+
f := "error_page.html"
17+
tmpl, err := template.ParseFS(errorHTML, f)
18+
if err != nil {
19+
panic(fmt.Errorf("RenderErrorPage Error: %s not found", f))
20+
}
21+
return func(c *fiber.Ctx) error {
22+
if err := c.Next(); err != nil {
23+
if strings.Contains(c.Get("Accept"), "text/html") {
24+
c.Set("Content-Type", "text/html")
25+
tmpl.Execute(c.Response().BodyWriter(), err.Error())
26+
return nil
27+
}
28+
return c.SendString(err.Error())
29+
}
30+
return err
31+
}
32+
}

handlers/error_page.html

+238
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<link rel="stylesheet" href="/styles.css" />
7+
<script src="/script.js" defer></script>
8+
<script>
9+
const handleThemeChange = () => {
10+
let theme = localStorage.getItem("theme");
11+
if (theme === null) {
12+
localStorage.setItem("theme", "system");
13+
theme = "system";
14+
}
15+
if (
16+
theme === "dark" ||
17+
(theme === "system" &&
18+
window.matchMedia("(prefers-color-scheme: dark)").matches)
19+
) {
20+
document.documentElement.classList.add("dark");
21+
} else {
22+
document.documentElement.classList.remove("dark");
23+
}
24+
};
25+
handleThemeChange();
26+
</script>
27+
<title>ladder | error</title>
28+
</head>
29+
30+
<body
31+
class="antialiased bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-200"
32+
>
33+
<div class="flex flex-col gap-4 max-w-3xl mx-auto pt-10">
34+
<div class="flex justify-between place-items-center">
35+
<div
36+
class="hover:drop-shadow-[0_0px_4px_rgba(122,167,209,.3)] ring-offset-white dark:ring-offset-slate-900 transition-colors duration-300 focus:outline-none focus:ring ring-offset-2"
37+
>
38+
<div class="flex">
39+
<a
40+
href="/"
41+
aria-label="ladder"
42+
class="flex -ml-2 h-8 font-extrabold tracking-tight no-underline focus:outline-none ring-offset-white dark:ring-offset-slate-900 focus:ring ring-offset-2"
43+
>
44+
<svg
45+
xmlns="http://www.w3.org/2000/svg"
46+
xmlns:xlink="http://www.w3.org/1999/xlink"
47+
viewBox="0 0 512 512"
48+
class="h-8 focus:outline-none focus:ring ring-offset-white dark:ring-offset-slate-900 ring-offset-2"
49+
>
50+
<path
51+
fill="#7AA7D1"
52+
d="M262.074 485.246C254.809 485.265 247.407 485.534 240.165 484.99L226.178 483.306C119.737 468.826 34.1354 383.43 25.3176 274.714C24.3655 262.975 23.5876 253.161 24.3295 241.148C31.4284 126.212 123.985 31.919 238.633 24.1259L250.022 23.8366C258.02 23.8001 266.212 23.491 274.183 24.1306C320.519 27.8489 366.348 45.9743 402.232 75.4548L416.996 88.2751C444.342 114.373 464.257 146.819 475.911 182.72L480.415 197.211C486.174 219.054 488.67 242.773 487.436 265.259L486.416 275.75C478.783 352.041 436.405 418.1 369.36 455.394L355.463 462.875C326.247 477.031 294.517 484.631 262.074 485.246ZM253.547 72.4475C161.905 73.0454 83.5901 144.289 73.0095 234.5C69.9101 260.926 74.7763 292.594 83.9003 317.156C104.53 372.691 153.9 416.616 211.281 430.903C226.663 434.733 242.223 436.307 258.044 436.227C353.394 435.507 430.296 361.835 438.445 267.978C439.794 252.442 438.591 236.759 435.59 221.5C419.554 139.955 353.067 79.4187 269.856 72.7052C264.479 72.2714 258.981 72.423 253.586 72.4127L253.547 72.4475Z"
53+
/>
54+
<path
55+
fill="#7AA7D1"
56+
d="M153.196 310.121L133.153 285.021C140.83 283.798 148.978 285.092 156.741 284.353L156.637 277.725L124.406 278.002C123.298 277.325 122.856 276.187 122.058 275.193L116.089 267.862C110.469 260.975 103.827 254.843 98.6026 247.669C103.918 246.839 105.248 246.537 111.14 246.523L129.093 246.327C130.152 238.785 128.62 240.843 122.138 240.758C111.929 240.623 110.659 242.014 105.004 234.661L97.9953 225.654C94.8172 221.729 91.2219 218.104 88.2631 214.005C84.1351 208.286 90.1658 209.504 94.601 209.489L236.752 209.545C257.761 209.569 268.184 211.009 285.766 221.678L285.835 206.051C285.837 197.542 286.201 189.141 284.549 180.748C280.22 158.757 260.541 143.877 240.897 135.739C238.055 134.561 232.259 133.654 235.575 129.851C244.784 119.288 263.680 111.990 277.085 111.105C288.697 109.828 301.096 113.537 311.75 117.703C360.649 136.827 393.225 183.042 398.561 234.866C402.204 270.253 391.733 308.356 367.999 335.1C332.832 374.727 269.877 384.883 223.294 360.397C206.156 351.388 183.673 333.299 175.08 316.6C173.511 313.551 174.005 313.555 170.443 313.52L160.641 313.449C158.957 313.435 156.263 314.031 155.122 312.487L153.196 310.121Z"
57+
/>
58+
</svg>
59+
<span class="text-3xl ml-1 text-[#7AA7D1] leading-8 align-middle"
60+
>ladder</span
61+
>
62+
</a>
63+
</div>
64+
</div>
65+
66+
<div class="flex justify-center z-10">
67+
<div class="relative" id="dropdown">
68+
<button
69+
aria-expanded="false"
70+
id="dropdownButton"
71+
aria-label="Toggle dropdown menu"
72+
onclick="toggleDropdown()"
73+
type="button"
74+
class="inline-flex items-center justify-center whitespace-nowrap rounded-full h-12 px-4 py-2 text-sm font-medium text-slate-600 dark:text-slate-400 ring-offset-white dark:ring-offset transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-white dark:bg-slate-900 hover:bg-slate-200 dark:hover:bg-slate-700 hover:text-slate-500 dark:hover:text-slate-200"
75+
>
76+
<svg
77+
xmlns="http://www.w3.org/2000/svg"
78+
viewBox="0 0 24 24"
79+
fill="none"
80+
stroke="currentColor"
81+
stroke-width="2"
82+
stroke-linecap="round"
83+
stroke-linejoin="round"
84+
class="h-5 w-5"
85+
>
86+
<path
87+
d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"
88+
/>
89+
<circle cx="12" cy="12" r="3" />
90+
</svg>
91+
</button>
92+
93+
<div
94+
id="dropdown_panel"
95+
class="hidden absolute right-0 mt-2 w-52 rounded-md bg-white dark:bg-slate-900 shadow-md border border-slate-400 dark:border-slate-700"
96+
>
97+
<div
98+
class="flex flex-col gap-2 w-full first-of-type:rounded-t-md last-of-type:rounded-b-md px-4 py-2.5 text-left text-sm"
99+
>
100+
Appearance
101+
<div class="grid grid-cols-4 gap-2">
102+
<div>
103+
<input
104+
type="radio"
105+
name="theme"
106+
id="light"
107+
value="light"
108+
class="peer hidden"
109+
/>
110+
<label
111+
for="light"
112+
tabindex="0"
113+
title="Light"
114+
class="flex items-end justify-center h-10 w-10 cursor-pointer select-none rounded-md p-2 text-sm text-slate-600 dark:text-slate-200 text-center hover:bg-slate-200 dark:hover:bg-slate-700 peer-checked:bg-slate-200 dark:peer-checked:bg-slate-700"
115+
>
116+
<svg
117+
xmlns="http://www.w3.org/2000/svg"
118+
viewBox="0 0 24 24"
119+
fill="none"
120+
stroke="currentColor"
121+
stroke-width="2"
122+
stroke-linecap="round"
123+
stroke-linejoin="round"
124+
class="h-5 w-5"
125+
>
126+
<circle cx="12" cy="12" r="4" />
127+
<path d="M12 2v2" />
128+
<path d="M12 20v2" />
129+
<path d="m4.93 4.93 1.41 1.41" />
130+
<path d="m17.66 17.66 1.41 1.41" />
131+
<path d="M2 12h2" />
132+
<path d="M20 12h2" />
133+
<path d="m6.34 17.66-1.41 1.41" />
134+
<path d="m19.07 4.93-1.41 1.41" />
135+
</svg>
136+
</label>
137+
</div>
138+
<div>
139+
<input
140+
type="radio"
141+
name="theme"
142+
id="dark"
143+
value="dark"
144+
class="peer hidden"
145+
/>
146+
<label
147+
for="dark"
148+
tabindex="0"
149+
title="Dark"
150+
class="flex items-end justify-center h-10 w-10 cursor-pointer select-none rounded-md p-2 text-base text-slate-600 dark:text-slate-200 text-center hover:bg-slate-200 dark:hover:bg-slate-700 peer-checked:bg-slate-200 dark:peer-checked:bg-slate-700"
151+
>
152+
<svg
153+
xmlns="http://www.w3.org/2000/svg"
154+
width="24"
155+
height="24"
156+
viewBox="0 0 24 24"
157+
fill="none"
158+
stroke="currentColor"
159+
stroke-width="2"
160+
stroke-linecap="round"
161+
stroke-linejoin="round"
162+
class="h-5 w-5"
163+
>
164+
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" />
165+
</svg>
166+
</label>
167+
</div>
168+
<div>
169+
<input
170+
type="radio"
171+
name="theme"
172+
id="system"
173+
value="system"
174+
class="peer hidden"
175+
checked
176+
/>
177+
<label
178+
for="system"
179+
tabindex="0"
180+
title="System preference"
181+
class="flex items-end justify-center h-10 w-10 cursor-pointer select-none rounded-md p-2 text-lg text-slate-600 dark:text-slate-200 text-center hover:bg-slate-200 dark:hover:bg-slate-700 peer-checked:bg-slate-200 dark:peer-checked:bg-slate-700"
182+
>
183+
<svg
184+
xmlns="http://www.w3.org/2000/svg"
185+
width="24"
186+
height="24"
187+
viewBox="0 0 24 24"
188+
fill="none"
189+
stroke="currentColor"
190+
stroke-width="2"
191+
stroke-linecap="round"
192+
stroke-linejoin="round"
193+
class="h-5 w-5"
194+
>
195+
<path d="M12 8a2.83 2.83 0 0 0 4 4 4 4 0 1 1-4-4" />
196+
<path d="M12 2v2" />
197+
<path d="M12 20v2" />
198+
<path d="m4.9 4.9 1.4 1.4" />
199+
<path d="m17.7 17.7 1.4 1.4" />
200+
<path d="M2 12h2" />
201+
<path d="M20 12h2" />
202+
<path d="m6.3 17.7-1.4 1.4" />
203+
<path d="m19.1 4.9-1.4 1.4" />
204+
</svg>
205+
</label>
206+
</div>
207+
</div>
208+
</div>
209+
</div>
210+
</div>
211+
</div>
212+
</div>
213+
214+
<div class="flex flex-col space-y-3">
215+
<h1>Error</h1>
216+
<div class="my-4"></div>
217+
<code class="p-4 mx-auto text-red-500 dark:text-red-400"> {{.}} </code>
218+
</div>
219+
220+
<footer class="mx-4 my-2 text-center text-slate-600 dark:text-slate-400">
221+
<small>
222+
<a
223+
href="https://github.com/everywall"
224+
class="hover:text-blue-500 dark:hover:text-blue-500 hover:underline underline-offset-2 transition-colors duration-300"
225+
>Everywall</a
226+
>
227+
|
228+
<a
229+
href="https://github.com/everywall/ladder"
230+
class="hover:text-blue-500 dark:hover:text-blue-500 hover:underline underline-offset-2 transition-colors duration-300"
231+
>Source</a
232+
>
233+
| Code Licensed Under GPL v3.0
234+
</small>
235+
</footer>
236+
</div>
237+
</body>
238+
</html>

handlers/form.html

+14-6
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,21 @@
282282
</a>
283283
</div>
284284

285-
<footer class="mx-4 text-center text-slate-600 dark:text-slate-400">
286-
<p>
287-
Code Licensed Under GPL v3.0 |
288-
<a href="https://github.com/everywall/ladder">View Source</a>
285+
<footer class="mx-4 my-2 text-center text-slate-600 dark:text-slate-400">
286+
<small>
287+
<a
288+
href="https://github.com/everywall"
289+
class="hover:text-blue-500 dark:hover:text-blue-500 hover:underline underline-offset-2 transition-colors duration-300"
290+
>Everywall</a
291+
>
289292
|
290-
<a href="https://github.com/everywall">Everywall</a>
291-
</p>
293+
<a
294+
href="https://github.com/everywall/ladder"
295+
class="hover:text-blue-500 dark:hover:text-blue-500 hover:underline underline-offset-2 transition-colors duration-300"
296+
>Source</a
297+
>
298+
| Code Licensed Under GPL v3.0
299+
</small>
292300
</footer>
293301
</div>
294302

handlers/playground.html

+8-10
Original file line numberDiff line numberDiff line change
@@ -361,23 +361,21 @@
361361
class="mt-48 h-[calc(100vh-14.5rem)] w-full overflow-x-hidden overflow-y-auto border-t-2 border-b-2 border-slate-400 dark:border-slate-700"
362362
></iframe>
363363

364-
<footer
365-
class="fixed bottom-0 inset-x-0 mx-4 h-10 text-center max-w-3xl lg:mx-auto py-2 text-slate-600 dark:text-slate-400"
366-
>
367-
<p>
368-
Code Licensed Under GPL v3.0 |
364+
<footer class="mx-4 my-2 text-center text-slate-600 dark:text-slate-400">
365+
<small>
369366
<a
370-
href="https://github.com/everywall/ladder"
367+
href="https://github.com/everywall"
371368
class="hover:text-blue-500 dark:hover:text-blue-500 hover:underline underline-offset-2 transition-colors duration-300"
372-
>View Source</a
369+
>Everywall</a
373370
>
374371
|
375372
<a
376-
href="https://github.com/everywall"
373+
href="https://github.com/everywall/ladder"
377374
class="hover:text-blue-500 dark:hover:text-blue-500 hover:underline underline-offset-2 transition-colors duration-300"
378-
>Everywall</a
375+
>Source</a
379376
>
380-
</p>
377+
| Code Licensed Under GPL v3.0
378+
</small>
381379
</footer>
382380
<div
383381
id="modalContainer"

handlers/styles.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proxychain/proxychain.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package proxychain
33
import (
44
"errors"
55
"fmt"
6-
http "github.com/bogdanfinn/fhttp"
7-
tls_client "github.com/bogdanfinn/tls-client"
8-
profiles "github.com/bogdanfinn/tls-client/profiles"
96
"io"
107
"log"
118
"net/url"
129
"strings"
1310

11+
http "github.com/bogdanfinn/fhttp"
12+
tls_client "github.com/bogdanfinn/tls-client"
13+
profiles "github.com/bogdanfinn/tls-client/profiles"
14+
1415
"github.com/gofiber/fiber/v2"
1516
)
1617

@@ -398,7 +399,7 @@ func (chain *ProxyChain) abort(err error) error {
398399
} else {
399400
e = fmt.Errorf("ProxyChain error: '%s'", err.Error())
400401
}
401-
chain.Context.SendString(e.Error())
402+
// chain.Context.SendString(e.Error()) // <- RenderErrorPage middleware to render error
402403
log.Println(e.Error())
403404
return e
404405
}

0 commit comments

Comments
 (0)