File tree Expand file tree Collapse file tree 3 files changed +78
-5
lines changed Expand file tree Collapse file tree 3 files changed +78
-5
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ func NewUIHandler(logger log.Logger) http.Handler {
2323 mux .HandleFunc ("/" , h .serveIndex )
2424 mux .HandleFunc ("/add" , h .serveAddPage )
2525 mux .HandleFunc ("/success" , h .serveSuccessPage )
26+ mux .HandleFunc ("/error" , h .serveErrorPage )
2627
2728 return mux
2829}
@@ -32,17 +33,17 @@ func (h *UIHandler) serveIndex(w http.ResponseWriter, r *http.Request) {
3233 err := templates .IndexPage (templates.IndexPageProps {
3334 Servers : []domain.ServerItem {
3435 {
35- ID : "1" ,
36+ ID : "1" ,
3637 Name : "Server Alpha" ,
3738 IP : "192.168.1.10" ,
3839 },
3940 {
40- ID : "2" ,
41+ ID : "2" ,
4142 Name : "Server Beta" ,
4243 IP : "192.168.1.11" ,
4344 },
4445 {
45- ID : "3" ,
46+ ID : "3" ,
4647 Name : "Server Charlie" ,
4748 IP : "192.168.1.12" ,
4849 },
@@ -83,3 +84,20 @@ func (h *UIHandler) serveSuccessPage(w http.ResponseWriter, r *http.Request) {
8384 http .Error (w , "failed to render page" , http .StatusInternalServerError )
8485 }
8586}
87+
88+ func (h * UIHandler ) serveErrorPage (w http.ResponseWriter , r * http.Request ) {
89+ errorText := r .URL .Query ().Get ("error" )
90+
91+ var text string
92+
93+ if errorText != "" {
94+ text = fmt .Sprintf ("Operation failed. Reason: '%s'" , errorText )
95+ }
96+
97+ err := templates .ErrorPage (templates.ErrorPageProps {Text : text }).Render (r .Context (), w )
98+
99+ if err != nil {
100+ h .log .Error ().Err (err ).Msg ("failed to render error page template" )
101+ http .Error (w , "failed to render page" , http .StatusInternalServerError )
102+ }
103+ }
Original file line number Diff line number Diff line change 1+ package templates
2+
3+ import (
4+ " github.com/co-browser/agent-browser/internal/web/templates/blocks"
5+ " github.com/co-browser/agent-browser/internal/web/templates/components"
6+ )
7+
8+ type ErrorPageProps struct {
9+ Text string
10+ }
11+
12+ css errorContainer () {
13+ padding : 20px 16px ;
14+ display : flex ;
15+ flex-direction : column ;
16+ align-items : center ;
17+ justify-content : center ;
18+ }
19+
20+ css errorGoBackLink () {
21+ display : flex ;
22+ align-items : center ;
23+ justify-content : center ;
24+ height : 40px ;
25+ background-color : #ff4d4d ;
26+ color : white ;
27+ border : none ;
28+ border-radius : 4px ;
29+ }
30+
31+ css errorText () {
32+ text-align : center ;
33+ }
34+
35+ templ ErrorPageComponent (props ErrorPageProps ) {
36+ <section class ={ errorContainer () } data-testid =" error-page" >
37+ <h2 >Error</h2 >
38+ <div >
39+ if props.Text != " " {
40+ <p class ={ errorText () }>{ props.Text }</p >
41+ } else {
42+ <p class ={ errorText () }>Operation failed!</p >
43+ }
44+ @ components.Link (components.LinkProps {Name: " Go back to home" , Href : " /" , Class : errorGoBackLink ()})
45+ </div >
46+ </section >
47+ }
48+
49+ templ ErrorPage (props ErrorPageProps ) {
50+ @ blocks.Main (ErrorPageComponent (props))
51+ }
Original file line number Diff line number Diff line change @@ -28,14 +28,18 @@ css successGoBackLink() {
2828 border-radius : 4px ;
2929}
3030
31+ css successText () {
32+ text-align : center ;
33+ }
34+
3135templ SuccessPageComponent (props SuccessPageProps ) {
3236 <section class ={ successContainer () } data-testid =" success-page" >
3337 <h2 >Success</h2 >
3438 <div >
3539 if props.Text != " " {
36- <p >{ props.Text }</p >
40+ <p class ={ successText () } >{ props.Text }</p >
3741 } else {
38- <p >Operation completed successfully!</p >
42+ <p class ={ successText () } >Operation completed successfully!</p >
3943 }
4044 @ components.Link (components.LinkProps {Name: " Go back to home" , Href : " /" , Class : successGoBackLink ()})
4145 </div >
You can’t perform that action at this time.
0 commit comments