#lang scheme/base
(require "base.ss"
"depend.ss"
"script.ss"
)
(define default-handlers (make-immutable-hash-registry))
(define (default-handler-set! status handler)
(define (path-helper status)
(string-append "/" (number->string status)))
(registry-set! default-handlers
status
(if (script? handler)
handler
(make-script handler (make-*path (path-helper status)
(path-helper status)
(path-helper status)
(current-seconds))))))
(define (default-handler-ref status)
(registry-ref default-handlers status (lambda ()
(error 'unknown-status "~a" status))))
(define (default-handler-del! status)
(registry-del! default-handlers status))
(default-handler-set! 401
(lambda args
`(p "Please provide your credential to access the resource.")))
(default-handler-set! 403
(lambda args
`(p "You do not have permission to access the resource.")))
(default-handler-set! 404
(lambda args
`(p "We did not find what you are looking for.")))
(default-handler-set! 500
(lambda (e)
`(div (h3 "Error occured: ")
(p ,(exn-message e)))))
(provide/contract
(default-handler-set! (-> integer? procedure? any))
(default-handler-ref (-> integer? procedure?))
(default-handler-del! (-> integer? any))
)