<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Application error</title>
  <!-- htmllint tag-bans="false" -->
  <style>
  * { box-sizing: border-box; }
  html { width: 100%; height: 100%; }
  body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 18px; }
  .content { margin: 0 auto; width: 20rem;}
  pre { white-space: pre-wrap; background-color: #f8f8f8; padding: 0.5em; overflow-x: auto; }
  pre code { white-space: pre; }
  #traceback { display: none; }
  #show-traceback { position: fixed; bottom: 0; left: 50%; width: 10rem; margin-left: -5rem; padding: 0.5rem 0; text-align: center; cursor: pointer; opacity: 0.4; }
  </style>
  <!-- htmllint tag-bans="$previous" -->
</head>
<body>
  <section class="content">
    <h1>Application error</h1>
    <p>This application made a mistake.</p>
    {% set exception = kwargs['exc_info'][1] %}
    {% if hasattr(exception, 'reason') %}
      <p><strong>Reason:</strong> {{ exception.reason }}</p>
    {% end %}
    <pre>{{ repr(exception) }}</pre>
    <p>Details are on the server log.</p>
  </section>

  {% from gramex import conf %}
  {% if conf.app.settings.serve_traceback %}
    <div id="traceback">
      {% import traceback %}
      <pre><code>{{ ''.join(traceback.format_exception(*kwargs['exc_info'])) }}</code></pre>
      <p class="content">Traceback is only for development. Disable it in <code>gramex.yaml</code> with <code>app.settings.serve_traceback: false</code></p>
    </div>
    <p id="show-traceback">Show traceback</p>
    <script>
      var $show = document.getElementById('show-traceback')
      var $traceback = document.getElementById('traceback')
      $show.addEventListener('click', function() {
        $traceback.style.display = 'block'
        $show.style.display = 'none'
      }, false)
    </script>
  {% end %}
</body>

</html>
