From 9c7cc4197f5a162baa652f3e608a292d002a05d8 Mon Sep 17 00:00:00 2001 From: David Florness Date: Sat, 7 Mar 2020 13:02:45 -0700 Subject: [PATCH] Error messages from the bulletin should be put in the JSON body --- bulletin.rkt | 44 ++++++++++++++++++-------------------------- client.rkt | 5 +++-- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/bulletin.rkt b/bulletin.rkt index 146defc..6e792a2 100644 --- a/bulletin.rkt +++ b/bulletin.rkt @@ -75,21 +75,19 @@ (set-add! _peers (hasheq 'input input)) (response/jsexpr empty)) (response/jsexpr - empty - #:code 400 - #:message #"Bad Login"))) + "Bad Login" + #:code 400))) (response/jsexpr + "You may not register" empty - #:code 403 - #:message #"You may not register"))) + #:code 403))) (define (peer-count request) (if (eq? state 'committing) (response/jsexpr (set-count _peers)) (response/jsexpr - empty - #:code 403 - #:message #"Committing has not begun"))) + "Committing has not begun" + #:code 403))) (define (commit request) (if (eq? state 'committing) @@ -105,18 +103,16 @@ (set-count _peers)) (transition)) (response/jsexpr empty)) - (response/jsexpr empty - #:code 403 - #:message #"Not in the committing phase"))) + (response/jsexpr "Not in the committing phase" + #:code 403))) (define (peers request) (if (eq? state 'voting) (response/jsexpr (for/list ([v _peers]) (hash-ref v 'input))) (response/jsexpr - empty - #:code 403 - #:message #"Voting has not begun"))) + "Voting has not begun" + #:code 403))) (define (outputs request) (if (eq? state 'voting) @@ -134,9 +130,8 @@ (transition)) (response/jsexpr empty)) (response/jsexpr - empty - #:code 403 - #:message #"This election is not in the voting phase"))) + "This election is not in the voting phase" + #:code 403))) (define (_values request) (if (eq? state 'summing) @@ -144,9 +139,8 @@ (response/jsexpr (hash-ref _outputs input))) (response/jsexpr - empty - #:code 403 - #:message #"This election is not in the summing phase"))) + "This election is not in the summing phase" + #:code 403))) (define (sum request) (if (eq? state 'summing) @@ -157,9 +151,8 @@ (response/jsexpr empty)) (response/jsexpr - empty - #:code 403 - #:message #"This election is not in the summing phase"))) + "This election is not in the summing phase" + #:code 403))) (define (sums request) (if (eq? (length (hash-keys _sums)) @@ -167,9 +160,8 @@ (response/jsexpr _sums) (response/jsexpr - empty - #:code 403 - #:message #"The sums are not yet available"))) + "The sums are not yet available" + #:code 403))) (define-values (dispatcher url-generator) (dispatch-rules diff --git a/client.rkt b/client.rkt index 0c94775..c8b40d2 100644 --- a/client.rkt +++ b/client.rkt @@ -70,9 +70,10 @@ (let ([username (readline "Username: ")] [password (get-pass "Password: ")]) (with-handlers ([exn:fail:network:http:error? - (λ (exn) + (λ ([ex : exn:fail:network:http:error]) (newline) - (displayln "Login refused. Wrong credentials, perhaps?") + (displayln (format "Login refused: ~a" + (exn-message ex))) (exit))]) (post bulletin "/register" #:data -- 2.38.4