CSRF-failure view which converts the failed POST request into a GET
    and calls the original view with a sensible error message presented
    to the user.
    :param request: the HttpRequest
    :param reason: non-localised failure description
17592
def csrf_failure(request, reason=''):
    
    if _csrf_failed_view.no_moj_csrf:
        from django.views.csrf import csrf_failure

        return csrf_failure(request, reason=reason)

    # present a sensible error message to users
    if reason == REASON_NO_CSRF_COOKIE:
        reason = _('Please try again.') + ' ' + \
                 _('Make sure you haven’t disabled cookies.')
    elif reason == REASON_NO_REFERER:
        reason = _('Please try again.') + ' ' + \
                 _('Make sure you are using a modern web browser '
                   'such as Firefox or Google Chrome.')
    else:
        reason = _('Your browser failed a security check.') + ' ' + \
                 _('Please try again.')
    messages.error(request, reason)

    # convert into GET request and show view again
    request.method = 'GET'
    request.POST = QueryDict()

    # call the original view but set response status to forbidden
    response = _csrf_failed_view.callback(request, *_csrf_failed_view.args, **_csrf_failed_view.kwargs)
    if response.status_code == 200:
        response.status_code = 403
    return response
183257
def _request(self, method, url, query_or_data=None, **kwargs):
        

        if query_or_data is None:
            query_or_data = {}

        request_method = getattr(self, '_http_{0}'.format(method))
        response = retry_request(self)(request_method)(url, query_or_data, **kwargs)

        if self.raw_mode:
            return response

        if response.status_code >= 300:
            error = get_error(response)
            if self.raise_errors:
                raise error
            return error

        # Return response object on NoContent
        if response.status_code == 204 or not response.text:
            return response

        return ResourceBuilder(
            self,
            self.default_locale,
            response.json()
        ).build()
1269243
def get(self, request, *args, **kwargs):
        
        response = super().get(request, args, kwargs)
        try:
            response.render()
        except Http404:
            request.GET = request.GET.copy()
            request.GET['page'] = '1'
            response = super().get(request, args, kwargs)
            response.status_code = 404

        return response
802111
def handle_request_parsing_error(err, req, schema, error_status_code, error_headers):
    
    abort(error_status_code, errors=err.messages)
1263371
def form(request):
    
    if request.method == 'POST':
        url = request.POST['url']
        submit_url = '%s%shl=%s' % (
            url,
            '&' if '?' in url else '?',
            request.LANGUAGE_CODE
        )
        params = urllib.urlencode(request.POST)
        f = urllib2.urlopen(submit_url, params)
        text = f.read()
    else:
        text = _('Error: request type has to be POST')

    response = http.HttpResponse(text, mimetype="text/plain")
    return response
416368
def process_exception(self, request, exception):
        
        if isinstance(exception, HttpRedirectRequest):
            return HttpResponseRedirect(exception.url, status=exception.status)
        else:
            return None
1303093
function (req, res) {
    var error = new errors.NotFound('Page Does Not Exist');
    if (req.accepts('html') && (req.url.indexOf('/api/') !== 0)) {
      this.renderErrorPage('404', error, req, res);
    } else {
      this.renderError(error, req, res);
    }
  }
1345909
def request(self, request):
        
        if request is None:
            raise ValueError("Invalid value for `request`, must not be `None`")  # noqa: E501
        if request is not None and not re.search(r'^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$', request):  # noqa: E501
            raise ValueError(r"Invalid value for `request`, must be a follow pattern or equal to `/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/`")  # noqa: E501

        self._request = request
891351
def redirect_exception(self, exception):
        

        from django.http import QueryDict, HttpResponseRedirect

        query = QueryDict("").copy()
        query["error"] = exception.error
        query["error_description"] = exception.reason
        query["state"] = self.state

        return HttpResponseRedirect(self.redirect_uri.url + "?" + query.urlencode())
948338
def process_request(self, request):
        
        request.token = get_token(request)
        request.user = SimpleLazyObject(lambda: get_user(request))
        request._dont_enforce_csrf_checks = dont_enforce_csrf_checks(request)
1277117
def error_404(request, exception):
    """"""
    return django.http.HttpResponseNotFound(
        d1_common.types.exceptions.NotFound(
            0,
            'Invalid API endpoint',
            # Include the regexes the URL was tested against
            # traceInformation=str(exception),
            nodeId=django.conf.settings.NODE_IDENTIFIER,
        ).serialize_to_transport(xslt_url=django.urls.base.reverse('home_xslt')),
        d1_common.const.CONTENT_TYPE_XML,
    )
930364
def from_requests_error(cls, err):
        
        import requests
        if isinstance(err, requests.HTTPError):
            status_code = err.response.status_code
            return HTTP_ERRORS.get(status_code, cls)(error=err, response=err.response)
        else:
            return cls(error=err)
452561
def buildErrorResponse(self, request, error=None):
        
        if error is not None:
            cls, e, tb = error
        else:
            cls, e, tb = sys.exc_info()

        return generate_error(request, cls, e, tb, self.gateway.debug)
906689
private ModelAndView generateErrorView(final String code, final Object[] args, final HttpServletRequest request) {
        val modelAndView = new ModelAndView(this.failureView);
        modelAndView.addObject("code", StringEscapeUtils.escapeHtml4(code));
        val desc = StringEscapeUtils.escapeHtml4(this.context.getMessage(code, args, code, request.getLocale()));
        modelAndView.addObject("description", desc);
        return modelAndView;
    }
701863
function handleErrorRequest(result, req, res) {
    const err = _.isError(result.msg) ? result.msg : result;
    const finalResp = STATUSES[result.status] || STATUSES[err.message] || STATUSES['error'];
    finalResp.msg = err.message;
    if (isDebug) finalResp.ext = err;

    logRequestError(err, req, finalResp);

    res.status(finalResp.statusCode);
    const view = result.view || errorView;
    if (view) {
      returnHTML(view, finalResp, res);
    } else {
      returnJSON(finalResp, res);
    }
  }
1175470
def handler404(request, template_name='404.html'):
    
    t = loader.get_template(template_name) # You need to create a 404.html template.
    return http.HttpResponseNotFound(t.render(Context({
        'MEDIA_URL': settings.MEDIA_URL,
        'STATIC_URL': settings.STATIC_URL
    })))
159495
def request(self, service, data):
        
        _res = self._request(service, data)
        res = _res.json()[0][0]
        if res["success"] == True:
            return res["result"]
        else:
            err_msg = res["errmsg"]
            raise Exception("Request not successful: '{0}'".format(err_msg))