[mod_python] How to do your own error handler pages in mpservlets?

Rune Hansen rune.hansen at scanmine.com
Thu Apr 14 02:20:58 EDT 2005


On 14. apr. 2005, at 06.00, Scott Chapman wrote:

> I don't recall seeing any docs on how to do your own pages for error 
> returns, such as HTTP_FORBIDDEN, etc.
>
> Can someone give me some pointers?
>
> TIA,
> Scott

I've built up a library of error functions that I always include in my 
mod_python applications.
"""
def raise400(logmsg,server):
     """Log an explanatory error message and send 400 to the client"""
     apache.log_error(logmsg, apache.APLOG_ERR, server)
     raise apache.SERVER_RETURN, apache.HTTP_BAD_REQUEST

def raise401(logmsg,server):
     """Log an explanatory error message and send 401 to the client"""
     apache.log_error(logmsg, apache.APLOG_ERR, server)
     raise apache.SERVER_RETURN, apache.HTTP_UNAUTHORIZED

def raise403(logmsg,server):
     """Log an explanatory error message and send 403 to the client"""
     apache.log_error(logmsg, apache.APLOG_ERR, server)
     raise apache.SERVER_RETURN, apache.HTTP_FORBIDDEN

def raise404(logmsg,server):
     """Log an explanatory error message and send 404 to the client"""
     apache.log_error(logmsg, apache.APLOG_ERR, server)
     raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND

def raise415(logmsg,server):
     """Log an explanatory error message and send 415 to the client"""
     apache.log_error(logmsg, apache.APLOG_ERR, server)
     raise apache.SERVER_RETURN, apache.HTTP_UNSUPPORTED_MEDIA_TYPE

def raise500(logmsg,server):
     """Log an explanatory error message and send 500 to the client"""
     apache.log_error(logmsg, apache.APLOG_ERR, server)
     raise apache.SERVER_RETURN, apache.HTTP_INTERNAL_SERVER_ERROR

def raise501(logmsg,server):
     """Log an explanatory error message and send 501 to the client"""
     apache.log_error(logmsg, apache.APLOG_ERR, server)
     raise apache.SERVER_RETURN, apache.HTTP_NOT_IMPLEMENTED
"""

I think these are quite handy although they will only return Apaches 
default error pages.

regards
/rune

---------------------------------------------------------------------
Behind the firewall, nobody can hear you scream...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 2117 bytes
Desc: not available
Url : http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20050414/f0138388/attachment.bin


More information about the Mod_python mailing list