Skip to content

Commit 2cd3dba

Browse files
Chuckclaude
andcommitted
fix(web-ui): show error toast on non-JSON 4xx/5xx quick-action responses
In the catch block of all 11 hx-on:htmx:after-request handlers, check xhr.status >= 400 and downgrade s to 'error' so a failed action that returns an HTML error page (or other non-JSON body) surfaces as an error toast instead of the optimistic 'success'/'info' default. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f4e7fea commit 2cd3dba

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎web_interface/templates/v3/index.html‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ <h3 class="text-md font-medium text-gray-900 mb-4">Quick Actions</h3>
7373
<button hx-post="/api/v3/system/action"
7474
hx-vals='{"action": "start_display"}'
7575
hx-swap="none"
76-
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Display started',s='success'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) {} showNotification(m,s); }"
76+
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Display started',s='success'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) { s=(event.detail.xhr&&event.detail.xhr.status>=400?'error':s); } showNotification(m,s); }"
7777
class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-green-600 hover:bg-green-700">
7878
<i class="fas fa-play mr-2"></i>
7979
Start Display
@@ -82,7 +82,7 @@ <h3 class="text-md font-medium text-gray-900 mb-4">Quick Actions</h3>
8282
<button hx-post="/api/v3/system/action"
8383
hx-vals='{"action": "stop_display"}'
8484
hx-swap="none"
85-
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Display stopped',s='success'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) {} showNotification(m,s); }"
85+
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Display stopped',s='success'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) { s=(event.detail.xhr&&event.detail.xhr.status>=400?'error':s); } showNotification(m,s); }"
8686
class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-red-600 hover:bg-red-700">
8787
<i class="fas fa-stop mr-2"></i>
8888
Stop Display
@@ -91,7 +91,7 @@ <h3 class="text-md font-medium text-gray-900 mb-4">Quick Actions</h3>
9191
<button hx-post="/api/v3/system/action"
9292
hx-vals='{"action": "git_pull"}'
9393
hx-swap="none"
94-
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Code update completed',s='info'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) {} showNotification(m,s); }"
94+
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Code update completed',s='info'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) { s=(event.detail.xhr&&event.detail.xhr.status>=400?'error':s); } showNotification(m,s); }"
9595
class="inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50">
9696
<i class="fas fa-download mr-2"></i>
9797
Update Code
@@ -101,7 +101,7 @@ <h3 class="text-md font-medium text-gray-900 mb-4">Quick Actions</h3>
101101
hx-vals='{"action": "reboot_system"}'
102102
hx-confirm="Are you sure you want to reboot the system?"
103103
hx-swap="none"
104-
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='System rebooting...',s='info'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) {} showNotification(m,s); }"
104+
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='System rebooting...',s='info'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) { s=(event.detail.xhr&&event.detail.xhr.status>=400?'error':s); } showNotification(m,s); }"
105105
class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-yellow-600 hover:bg-yellow-700">
106106
<i class="fas fa-power-off mr-2"></i>
107107
Reboot System

‎web_interface/templates/v3/partials/overview.html‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ <h3 class="text-md font-medium text-gray-900 mb-4">Quick Actions</h3>
151151
<button hx-post="/api/v3/system/action"
152152
hx-vals='{"action": "start_display"}'
153153
hx-swap="none"
154-
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Display started',s='success'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) {} showNotification(m,s); }"
154+
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Display started',s='success'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) { s=(event.detail.xhr&&event.detail.xhr.status>=400?'error':s); } showNotification(m,s); }"
155155
class="inline-flex items-center px-4 py-2 border border-transparent text-base font-semibold rounded-md text-white bg-green-600 hover:bg-green-700">
156156
<i class="fas fa-play mr-2"></i>
157157
Start Display
@@ -160,7 +160,7 @@ <h3 class="text-md font-medium text-gray-900 mb-4">Quick Actions</h3>
160160
<button hx-post="/api/v3/system/action"
161161
hx-vals='{"action": "stop_display"}'
162162
hx-swap="none"
163-
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Display stopped',s='success'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) {} showNotification(m,s); }"
163+
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Display stopped',s='success'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) { s=(event.detail.xhr&&event.detail.xhr.status>=400?'error':s); } showNotification(m,s); }"
164164
class="inline-flex items-center px-4 py-2 border border-transparent text-base font-semibold rounded-md text-white bg-red-600 hover:bg-red-700">
165165
<i class="fas fa-stop mr-2"></i>
166166
Stop Display
@@ -170,7 +170,7 @@ <h3 class="text-md font-medium text-gray-900 mb-4">Quick Actions</h3>
170170
hx-vals='{"action": "git_pull"}'
171171
hx-confirm="This will stash any local changes and update the code. Continue?"
172172
hx-swap="none"
173-
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Code update completed',s='info'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) {} showNotification(m,s); }"
173+
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Code update completed',s='info'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) { s=(event.detail.xhr&&event.detail.xhr.status>=400?'error':s); } showNotification(m,s); }"
174174
class="inline-flex items-center px-4 py-2 border border-gray-300 text-base font-semibold rounded-md text-gray-900 bg-white hover:bg-gray-50">
175175
<i class="fas fa-download mr-2"></i>
176176
Update Code
@@ -180,7 +180,7 @@ <h3 class="text-md font-medium text-gray-900 mb-4">Quick Actions</h3>
180180
hx-vals='{"action": "reboot_system"}'
181181
hx-confirm="Are you sure you want to reboot the system?"
182182
hx-swap="none"
183-
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='System rebooting...',s='info'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) {} showNotification(m,s); }"
183+
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='System rebooting...',s='info'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) { s=(event.detail.xhr&&event.detail.xhr.status>=400?'error':s); } showNotification(m,s); }"
184184
class="inline-flex items-center px-4 py-2 border border-transparent text-base font-semibold rounded-md text-white bg-yellow-600 hover:bg-yellow-700">
185185
<i class="fas fa-power-off mr-2"></i>
186186
Reboot System
@@ -190,7 +190,7 @@ <h3 class="text-md font-medium text-gray-900 mb-4">Quick Actions</h3>
190190
hx-vals='{"action": "shutdown_system"}'
191191
hx-confirm="Are you sure you want to shut down the system? This will power off the Raspberry Pi."
192192
hx-swap="none"
193-
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='System shutting down...',s='info'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) {} showNotification(m,s); }"
193+
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='System shutting down...',s='info'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) { s=(event.detail.xhr&&event.detail.xhr.status>=400?'error':s); } showNotification(m,s); }"
194194
class="inline-flex items-center px-4 py-2 border border-transparent text-base font-semibold rounded-md text-white bg-red-800 hover:bg-red-900">
195195
<i class="fas fa-power-off mr-2"></i>
196196
Shutdown System
@@ -199,7 +199,7 @@ <h3 class="text-md font-medium text-gray-900 mb-4">Quick Actions</h3>
199199
<button hx-post="/api/v3/system/action"
200200
hx-vals='{"action": "restart_display_service"}'
201201
hx-swap="none"
202-
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Display service restarted',s='success'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) {} showNotification(m,s); }"
202+
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Display service restarted',s='success'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) { s=(event.detail.xhr&&event.detail.xhr.status>=400?'error':s); } showNotification(m,s); }"
203203
class="inline-flex items-center px-4 py-2 border border-gray-300 text-base font-semibold rounded-md text-gray-900 bg-white hover:bg-gray-50">
204204
<i class="fas fa-redo mr-2"></i>
205205
Restart Display Service
@@ -208,7 +208,7 @@ <h3 class="text-md font-medium text-gray-900 mb-4">Quick Actions</h3>
208208
<button hx-post="/api/v3/system/action"
209209
hx-vals='{"action": "restart_web_service"}'
210210
hx-swap="none"
211-
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Web service restarted',s='success'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) {} showNotification(m,s); }"
211+
hx-on:htmx:after-request="if (typeof showNotification !== 'undefined') { var m='Web service restarted',s='success'; try { var d=JSON.parse(event.detail.xhr.responseText); m=d.message||m; s=d.status||s; } catch(e) { s=(event.detail.xhr&&event.detail.xhr.status>=400?'error':s); } showNotification(m,s); }"
212212
class="inline-flex items-center px-4 py-2 border border-gray-300 text-base font-semibold rounded-md text-gray-900 bg-white hover:bg-gray-50">
213213
<i class="fas fa-redo mr-2"></i>
214214
Restart Web Service

0 commit comments

Comments
 (0)