def METHOD_NAME(environ, start_response):
    try:
        (status, c_type, output) = handler(environ)
    except HandlerError as exc:
        status = exc.status
        output = exc.output
        c_type = 'text/plain'
    except:
        (exc_type, exc_value, exc_traceback) = sys.exc_info()
        lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
        status = '500 Internal Server Error'
        output = ''.join(lines)
        c_type = 'text/plain'
    response_headers = [('Content-Type', c_type), ('Content-Length', str(len(output)))]
    if c_type == 'image/nifti':
        response_headers.append(('Content-Disposition', 'attachment; filename=image.nii'))
    start_response(status, response_headers)
    return [output]