Example #1
0
def error_response(error_code, error_message, error_class, error_dict=None):
    resp_dict = {}
    #    response = HttpResponse()
    response = HttpResponseServerError()

    resp_dict['error code'] = error_code
    resp_dict['error message'] = error_message
    resp_dict['error class'] = error_class
    #    if error_code == 500:
    #        response.status_code = error_code

    if error_dict:
        error_dict = ErrorDict(error_dict)
        resp_dict['error message'] += '\n%s' % error_dict.as_text()
    logger.debug('resp_dict%s' % resp_dict)
    response.write(json.dumps(resp_dict))
    logger.debug('response.content %s' % response.content)
    return response
Example #2
0
def error_response( error_code, error_message, error_class,  error_dict = None):
    resp_dict = {}
#    response = HttpResponse()
    response = HttpResponseServerError()

    resp_dict['error code'] = error_code
    resp_dict['error message'] = error_message
    resp_dict['error class'] = error_class
#    if error_code == 500:
#        response.status_code = error_code
    

    
    if error_dict:
        error_dict = ErrorDict(error_dict)
        resp_dict['error message'] += '\n%s'%error_dict.as_text() 
    logger.debug('resp_dict%s' %resp_dict)
    response.write(json.dumps(resp_dict))
    logger.debug('response.content %s' %response.content)
    return response
Example #3
0
    def render_to_response(self, context, **kwargs):
        encoding = self.get_encoding()
        context['encoding'] = encoding.upper()

        buffer = StringIO()
        html = render_to_string(self.get_template_names()[0], context)
        pdf = pisa.CreatePDF(StringIO(html.encode(encoding)), buffer, 
            show_error_as_pdf=True, encoding=encoding, 
            link_callback=fetch_resources)
        if pdf.err:
            response = HttpResponseServerError(
                    'Got %s errors trying to convert to pdf.' % pdf.err
                )
        else:
            response = HttpResponse(mimetype='application/pdf')
            response['Content-Disposition'] = \
                'attachment; filename=%s' % self.get_output_filename()
            response.write(buffer.getvalue())
        buffer.close()

        return response
Example #4
0
 def error(e):
     response = HttpResponseServerError()
     response.write(e)
     return response
Example #5
0
def view_500(request):
    response = HttpResponseServerError()
    response.write("Something went wrong")
    return response
Example #6
0
def view_500(request):
    response = HttpResponseServerError()
    template = loader.get_template('500.html')
    response.write(template.render(RequestContext(request)))
    return response
Example #7
0
 def error(e):
     response = HttpResponseServerError()
     response.write(e)
     return response