Skip to content

Commit

Permalink
new: Add error page
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Feb 18, 2019
1 parent 852fb70 commit 9f2b7f7
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 82 deletions.
134 changes: 65 additions & 69 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion lookyloo/exceptions.py
Expand Up @@ -3,8 +3,12 @@


class LookylooException(Exception):
pass
pass


class MissingEnv(LookylooException):
pass


class NoValidHarFile(LookylooException):
pass
1 change: 0 additions & 1 deletion lookyloo/helpers.py
Expand Up @@ -43,7 +43,6 @@ def get_socket_path(name: str) -> str:

def check_running(name: str) -> bool:
socket_path = get_socket_path(name)
print(socket_path)
try:
r = Redis(unix_socket_path=socket_path)
if r.ping():
Expand Down
20 changes: 12 additions & 8 deletions lookyloo/lookyloo.py
Expand Up @@ -4,7 +4,7 @@
import json

from scrapysplashwrapper import crawl
from har2tree import CrawledTree
from har2tree import CrawledTree, Har2TreeError
import pickle

from datetime import datetime
Expand All @@ -21,6 +21,7 @@

from pathlib import Path
from .helpers import get_homedir, get_socket_path
from .exceptions import NoValidHarFile
from redis import Redis

import logging
Expand Down Expand Up @@ -109,13 +110,16 @@ def process_scrape_queue(self):

def load_tree(self, report_dir: Path):
har_files = sorted(report_dir.glob('*.har'))
ct = CrawledTree(har_files)
ct.find_parents()
ct.join_trees()
temp = tempfile.NamedTemporaryFile(prefix='lookyloo', delete=False)
pickle.dump(ct, temp)
temp.close()
return temp.name, ct.to_json(), ct.start_time.isoformat(), ct.user_agent, ct.root_url
try:
ct = CrawledTree(har_files)
ct.find_parents()
ct.join_trees()
temp = tempfile.NamedTemporaryFile(prefix='lookyloo', delete=False)
pickle.dump(ct, temp)
temp.close()
return temp.name, ct.to_json(), ct.start_time.isoformat(), ct.user_agent, ct.root_url
except Har2TreeError as e:
raise NoValidHarFile(e.message)

def cleanup_old_tmpfiles(self):
for tmpfile in pathlib.Path(tempfile.gettempdir()).glob('lookyloo*'):
Expand Down
10 changes: 7 additions & 3 deletions website/web/__init__.py
Expand Up @@ -12,6 +12,7 @@

from lookyloo.helpers import get_homedir
from lookyloo.lookyloo import Lookyloo
from lookyloo.exceptions import NoValidHarFile


app = Flask(__name__)
Expand Down Expand Up @@ -127,9 +128,12 @@ def tree(tree_uuid):
if not report_dir:
return redirect(url_for('index'))

tree_json, start_time, user_agent, root_url = load_tree(report_dir)
return render_template('tree.html', tree_json=tree_json, start_time=start_time,
user_agent=user_agent, root_url=root_url, tree_uuid=tree_uuid)
try:
tree_json, start_time, user_agent, root_url = load_tree(report_dir)
return render_template('tree.html', tree_json=tree_json, start_time=start_time,
user_agent=user_agent, root_url=root_url, tree_uuid=tree_uuid)
except NoValidHarFile as e:
return render_template('error.html', error_message=e.message)


@app.route('/', methods=['GET'])
Expand Down
9 changes: 9 additions & 0 deletions website/web/templates/error.html
@@ -0,0 +1,9 @@
{% extends "main.html" %}
{% block title %}Error{% endblock %}

{% block content %}
<div class="container">
<h1>Something went wrong</h1>
<b>{{ error_message }}</b>
</div>
{% endblock %}

0 comments on commit 9f2b7f7

Please sign in to comment.