Colubrid Exceptions

Colubrid ships a list of exceptions which should be used in applications. All these exceptions are located in colubrid.exceptions.

Custom error pages

Colubrid includes a module called colubrid.exceptions. It contains a number of Python exceptions that inherit from colubrid.exceptions.HttpException.

When you raise an HttpException, colubrid will call the method process_http_exception with the error instance as argument. You can easily create your own error pages by overwriting that method:

from colubrid import BaseApplication, HttpResponse, execute
from colubrid.exceptions import PageNotFound

class MyApplication(BaseApplication):

    def process_request(self):
        raise PageNotFound

    def process_http_exception(self, e):
        if e.code == 404:
            return HttpResponse('''
            <h1>Page not Found</h1>
            <p>the requested page does not exist.</p>
            ''', status=404)
        return super(MyApplication, self).process_http_exception(e)

app = MyApplication

if __name__ == '__main__':
    execute(app)

This example would overwrite only the 404 error page, all other exceptions will still be passed to the original error page defined in BaseApplication.

Colubrid Errors

The following predefined errors are located in colubrid.exceptions and can be thrown using raise:

raise HttpRedirect('http://www.example.com/')

PageNotFound

code:404
title:Not Found
msg:The resource could not be found.

PageGone

code:410
title:Gone
msg:This resource is no longer available. No forwarding address is given.

AccessDenied

code:403
title:Forbidden
msg:Access was denied to this resource.

BadRequest

code:400
title:Bad Request
msg:The server could not comply with the request since it is either malformed or otherwise incorrect.

RequestTimeout

code:408
title:Request Timeout
msg:There was a conflict when trying to complete your request.

ServerError

code:500
title:Internal Server Error
msg:The server has either erred or is incapable of performing the requested operation.

HttpRedirect

code:307
title:Temporary Redirect
msg:The resource has been moved to %s.

HttpFound

code:302
title:Found
msg:The resource was found at %s.

HttpMoved

code:301
title:Moved Permanently
msg:The resource has been moved to %s.
Last Change: 10 Sep 2006 17:12:27 | show source