guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

05/06: Add a JSON error page


From: Christopher Baines
Subject: 05/06: Add a JSON error page
Date: Fri, 21 Jun 2024 07:30:47 -0400 (EDT)

cbaines pushed a commit to branch master
in repository data-service.

commit 94e66d5b1fe4d8b852bfb403196166db4ccd1f3a
Author: Christopher Baines <mail@cbaines.net>
AuthorDate: Fri Jun 21 11:04:57 2024 +0100

    Add a JSON error page
---
 guix-data-service/web/controller.scm | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/guix-data-service/web/controller.scm 
b/guix-data-service/web/controller.scm
index d503052..a20e761 100644
--- a/guix-data-service/web/controller.scm
+++ b/guix-data-service/web/controller.scm
@@ -718,11 +718,20 @@
        startup-controller-thunk)
    #:on-error 'backtrace
    #:post-error (lambda args
-                  (render-html #:sxml (error-page
-                                       (if (%show-error-details)
-                                           args
-                                           #f))
-                               #:code 500))))
+                  (case (most-appropriate-mime-type
+                         '(application/json text/html)
+                         mime-types)
+                    ((application/json)
+                     (render-json `((error . ,(if (%show-error-details)
+                                                  (simple-format #f "~A" args)
+                                                  #f)))
+                                  #:code 500))
+                    (else
+                     (render-html #:sxml (error-page
+                                          (if (%show-error-details)
+                                              args
+                                              #f))
+                                  #:code 500))))))
 
 (define* (base-controller request method-and-path-components
                           startup-completed?)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]