{% extends "page.html" %}

{% block login_widget %}
{% endblock %}

{% block main %}

<div class="error">
  {% block h1_error %}
  <h1>
    {{status_code}} : {{status_message}}
  </h1>
  {% endblock h1_error %}
  {% block error_detail %}
  {% if message %}
  <p>
    {{message}}
  </p>
  {% endif %}
  {% if message_html %}
  <p>
    {{message_html | safe}}
  </p>
  {% endif %}
  {% if extra_error_html %}
  <p>
    {{extra_error_html | safe}}
  </p>
  {% endif %}
  {% endblock error_detail %}
</div>

{% endblock %}

{% block script %}
  {{super()}}

  <script type="text/javascript">
    function _remove_redirects_from_url() {
      if (window.location.search.length <= 1) {
        return;
      }
      var search_parameters = window.location.search.slice(1).split('&');
      for (var i = 0; i < search_parameters.length; i++) {
        if (search_parameters[i].split('=')[0] === 'redirects') {
          // remote redirects from search parameters
          search_parameters.splice(i, 1);
          var new_search = '';
          if (search_parameters.length) {
            new_search = '?' + search_parameters.join('&');
          }
          var new_url = window.location.origin +
                        window.location.pathname +
                        new_search +
                        window.location.hash;
          window.history.replaceState({}, "", new_url);
          return;
        }
      }
    }

    _remove_redirects_from_url();
  </script>
{% endblock %}