Hi all,

Using 6.0.1

I was under the (maybe mistaken) impression that calling response/... terminated the servlet thread. It seems though that it doesn't. I was hoping to use response as an early exit, so that my servlets look like: e.g.,

(define (user/exists request)
  (let* [
         (params   (request-bindings request))
         (username (exists-binding? 'username params))
         (response (make-hash))
        ]

    ; validate request
    (unless username
      (response/json (hasheq 'success #f 'msg "missing username" ))

    ; get request parameters
    (set! username (extract-binding/single 'username params))

    :

    ; send a real response
    (response/json response )
    ))


(define (response/json obj . cookies )
  (response/output
      (λ (op) (write-json obj op))
      #:code 200
      #:message #"OK"
      #:seconds (current-seconds)
      #:mime-type #"application/javascript"
      #:headers (map cookie->header cookies)
      ))

I expected that unless would bail out if the test fails. However, execution charges ahead into code that extracts post parameters and/or cookie values and then I get a contract error that terminates the servlet ... usually before my own error response is sent.

Is response supposed to terminate the servlet? If not, can I wrap a let/ec around the whole servlet and do something like:

(define (user/exists request)
  (let/ec fail
     (let* [
            (params   (request-bindings request))
            (username (exists-binding? 'username params))
            (response (make-hash))
        ]

       ; validate request
       (unless username
         (response/json (hasheq 'success #f 'msg "missing username" )
          (fail))

       ; get request parameters
       (set! username (extract-binding/single 'username params))

       :

       ; send a real response
       (response/json response )
       )))

or do I have to arrange that the response always is the last value produced?

Thanks,
George

____________________
 Racket Users list:
 http://lists.racket-lang.org/users

Reply via email to