2000-09-26 10:35:26 -04:00
|
|
|
;;; Error stuff for the http server. -*- Scheme -*-
|
2002-08-27 05:03:22 -04:00
|
|
|
|
|
|
|
;;; This file is part of the Scheme Untergrund Networking package.
|
|
|
|
|
|
|
|
;;; For copyright information, see the file COPYING which comes with
|
|
|
|
;;; the distribution.
|
2000-09-26 10:35:26 -04:00
|
|
|
|
|
|
|
;;; An http error condition is a data structure with the following pieces:
|
|
|
|
;;; (error-code request message . irritants)
|
|
|
|
;;; You recognise one with HTTP-ERROR?, and retrieve the pieces with
|
|
|
|
;;; CONDITION-STUFF.
|
|
|
|
;;;
|
|
|
|
|
|
|
|
;;; HTTP error condition
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;; Define a sub-type of the S48 error condition, the HTTP error condition.
|
2002-08-26 05:59:14 -04:00
|
|
|
;;; An HTTP error is one that corresponds to one of the HTTP error response
|
2000-09-26 10:35:26 -04:00
|
|
|
;;; codes, so you can reliably use an HTTP error condition to construct an
|
2002-08-26 05:59:14 -04:00
|
|
|
;;; error response message to send back to the HTTP client.
|
2000-09-26 10:35:26 -04:00
|
|
|
|
|
|
|
(define-condition-type 'http-error '(error))
|
|
|
|
|
|
|
|
(define http-error? (condition-predicate 'http-error))
|
|
|
|
|
2004-08-11 05:20:31 -04:00
|
|
|
;; See make-error-response for what you have to stuff into args for
|
|
|
|
;; each status-code. (All http-errors will be caught by the top-level
|
|
|
|
;; error-handler of process-toplevel-request, and will be turned into
|
|
|
|
;; calls of make-error-response).
|
2002-08-26 05:59:14 -04:00
|
|
|
(define (http-error status-code req . args)
|
|
|
|
(apply signal 'http-error status-code req args))
|
2000-09-26 10:35:26 -04:00
|
|
|
|
2004-08-11 05:20:31 -04:00
|
|
|
|
2000-09-26 10:35:26 -04:00
|
|
|
;;; Syntax error condition
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;; Scheme 48 has a "syntax error" error condition, but it isn't an error
|
|
|
|
;;; condition! It's a warning condition. I don't understand this.
|
|
|
|
;;; We define a *fatal* syntax error here for the parsers to use.
|
|
|
|
|
2004-08-11 05:20:31 -04:00
|
|
|
|
|
|
|
;; fatal-syntax-error isn't really a different type of error - it's
|
|
|
|
;; just an abbreviated notation:
|
|
|
|
;; (fatal-syntax-error msg irritants)
|
|
|
|
;; is equivalent to
|
|
|
|
;; (http-error (status-code bad-request) #f msg irritants)
|
|
|
|
;; -> use fatal-syntax-error where the client request cannot be parsed
|
|
|
|
;; because of bad syntax
|
|
|
|
|
2000-09-26 10:35:26 -04:00
|
|
|
(define-condition-type 'fatal-syntax-error '(error))
|
|
|
|
|
|
|
|
(define fatal-syntax-error? (condition-predicate 'fatal-syntax-error))
|
|
|
|
|
2004-08-11 05:20:31 -04:00
|
|
|
;; as with http-errors fatal-syntax-errors will be caught by the
|
|
|
|
;; top-level error-handler of process-toplevel-request and turned into
|
|
|
|
;; calls of make-error-response
|
2000-09-26 10:35:26 -04:00
|
|
|
(define (fatal-syntax-error msg . irritants)
|
|
|
|
(apply signal 'fatal-syntax-error msg irritants))
|
|
|
|
|
2004-08-11 05:20:31 -04:00
|
|
|
|