For a Django-Server I use several custom Error-Codes, error-titles and descriptions, possibly other fields might follow.
I'm using right now a basic global dictionary.
errordict = {'512':
{
'errorno': 512,
'errordescr': "Database Down",
'toDo': "Restart the database, Server: "+serveradr
},
'513' : ....
}
And in the code something like:
def handleError(s_err):
curerr=errordict[s_err]
logging.error("Error "+s_err+" occurred: "+curerr['errordescr'])
The usage looks like this:
try:
findEntry(s_id)
except NoSuchEntryEx as nsee:
s_err="513"
handleError(s_err)
return HttpResponse(render_to_string('error.html', {
'errorno': s_err,
'errordescr': mark_safe(str(nsee)
+ const.OUTPUT_NEWLINE),
'toDo': errordict[s_err]['toDo']
}))
I'm not happy with that and would rather define its own class - which would from the current perspective would just consist of this single, growing dict-object, which does not seem a great idea either.
It's of course a constant, every change there is hard-coded.
NoSuchEntryEx
- in this specific case there is just not much left to do for me on the server \$\endgroup\$