From 4f1743dad652d9a3781b268294b89d22c57528c0 Mon Sep 17 00:00:00 2001 From: Jakob L. Kreuze Date: Wed, 23 Nov 2022 19:16:45 -0500 Subject: [dynamic] Refactor and improve error reporting with R6RS exceptions --- haunt/jakob/dynamic/capabilities/gallery.scm | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'haunt/jakob/dynamic/capabilities/gallery.scm') diff --git a/haunt/jakob/dynamic/capabilities/gallery.scm b/haunt/jakob/dynamic/capabilities/gallery.scm index b8b46c9..ce154b9 100644 --- a/haunt/jakob/dynamic/capabilities/gallery.scm +++ b/haunt/jakob/dynamic/capabilities/gallery.scm @@ -18,6 +18,7 @@ #:use-module (ice-9 binary-ports) #:use-module (ice-9 ftw) #:use-module (ice-9 match) + #:use-module (jakob dynamic errors) #:use-module (jakob dynamic util) #:use-module (json) #:use-module (squee) @@ -72,14 +73,10 @@ (decode-form query-string) '())) (code (car (assoc-ref params "g")))) - (if (valid-gallery-code code) - (values '((content-type . (application/json))) - (scm->json-string `((info . ,(get-gallery-info code)) - (images . ,(get-gallery-images code))))) - (values (build-response #:code 400) - (scm->json-string - `((success . #f) - (error . "Invalid gallery code"))))))) + (unless (valid-gallery-code code) (panic "invalid gallery code")) + (values '((content-type . (application/json))) + (scm->json-string `((info . ,(get-gallery-info code)) + (images . ,(get-gallery-images code))))))) (define (image-exists? file-name) (define (string/= a b) (not (string= a b))) @@ -103,9 +100,5 @@ (decode-form query-string) '())) (file-name (car (assoc-ref params "name")))) - (if (image-exists? file-name) - (read-image file-name) - (values (build-response #:code 400) - (scm->json-string - `((success . #f) - (error . "Invalid filename"))))))) + (unless (image-exists? file-name) (panic "invalid filename")) + (read-image file-name))) -- cgit v1.3