Update exception handling for build events

This commit is contained in:
Christopher Baines 2025-04-01 22:43:15 +03:00
parent d60a8a44cb
commit 14de1667b1

View file

@ -277,8 +277,15 @@
(if (member provided-token (if (member provided-token
(map cdr permitted-tokens) (map cdr permitted-tokens)
string=?) string=?)
(catch (with-exception-handler
'json-invalid (lambda (exn)
(if (eq? (exception-kind exn) 'json-invalid)
(render-json
'((error . "could not parse body as JSON"))
#:code 400)
(render-json
'((error . "error"))
#:code 403)))
(lambda () (lambda ()
(let ((body-string (utf8->string body))) (let ((body-string (utf8->string body)))
(let* ((body-json (json-string->scm body-string)) (let* ((body-json (json-string->scm body-string))
@ -294,30 +301,27 @@
'((error . "no items to process")) '((error . "no items to process"))
#:code 400)) #:code 400))
(else (else
(catch (with-exception-handler
#t (lambda (exn)
(render-json
'((error . "could not process events"))
#:code 500))
(lambda () (lambda ()
(process-items items) (with-exception-handler
(no-content)) (lambda (exn)
(lambda (key . args) (print-backtrace-and-exception/knots exn)
(simple-format (current-error-port) (simple-format (current-error-port)
"error processing events: ~A: ~A\n" "error processing events: ~A\n"
key exn)
args)
(for-each (lambda (item) (for-each (lambda (item)
(simple-format (current-error-port) (simple-format (current-error-port)
" ~A\n" item)) " ~A\n" item))
items) items))
(render-json (lambda ()
'((error . "could not process events")) (process-items items)))
#:code 500)))))))) (no-content))
(lambda (key . args) #:unwind? #t))))))
(render-json #:unwind? #t)))))))
'((error . "could not parse body as JSON"))
#:code 400)))
(render-json
'((error . "error"))
#:code 403)))))))
(define (handle-signing-key-request id) (define (handle-signing-key-request id)
(render-html (render-html