Skip to content

Commit

Permalink
Add endpoint for logging uncaught client exceptions (hedyorg#498)
Browse files Browse the repository at this point in the history
* Add endpoint for logging uncaught client exceptions
  • Loading branch information
fpereiro authored Jun 18, 2021
1 parent 62143f3 commit 302d44b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,21 @@ def report_error():

return 'logged'

@app.route('/client_exception', methods=['POST'])
def report_client_exception():
post_body = request.json

querylog.log_value(
session=session_id(),
date=str(datetime.datetime.now()),
client_error=post_body,
version=version(),
username=current_user(request) ['username'] or None,
is_test=1 if os.getenv ('IS_TEST_ENV') else None
)

return 'logged', 500

@app.route('/version', methods=['GET'])
def version_page():
"""
Expand Down
17 changes: 17 additions & 0 deletions static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,23 @@ function reportClientError(level, code, client_error) {
});
}

window.onerror = function reportClientException(message, source, line_number, column_number, error) {

$.ajax({
type: 'POST',
url: '/client_exception',
data: JSON.stringify({
message: message,
source: source,
line_number: line_number,
column_number: column_number,
error: error
}),
contentType: 'application/json',
dataType: 'json'
});
}

function runPythonProgram(code, cb) {
const outputDiv = $('#output');
outputDiv.empty();
Expand Down

0 comments on commit 302d44b

Please sign in to comment.