~edwargix/tallyard

9c7cc4197f5a162baa652f3e608a292d002a05d8 — David Florness 5 years ago 2d5e5b2
Error messages from the bulletin should be put in the JSON body
2 files changed, 21 insertions(+), 28 deletions(-)

M bulletin.rkt
M client.rkt
M bulletin.rkt => bulletin.rkt +18 -26
@@ 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

M client.rkt => client.rkt +3 -2
@@ 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