aboutsummaryrefslogtreecommitdiff
path: root/haunt/jakob/dynamic/capabilities/gallery.scm
diff options
context:
space:
mode:
authorJakob L. Kreuze2022-11-23 19:16:45 -0500
committerJakob L. Kreuze2022-11-23 19:23:26 -0500
commit4f1743dad652d9a3781b268294b89d22c57528c0 (patch)
treed15ead9c06b7140f383bcc09c0058963933aea6d /haunt/jakob/dynamic/capabilities/gallery.scm
parent2a7b250df5fa9611c2270c5837fab9fab750563c (diff)
[dynamic] Refactor and improve error reporting with R6RS exceptions
Diffstat (limited to 'haunt/jakob/dynamic/capabilities/gallery.scm')
-rw-r--r--haunt/jakob/dynamic/capabilities/gallery.scm21
1 files changed, 7 insertions, 14 deletions
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)))

© 2015 - 2026 Jakob L. Kreuze