From fb98509789cd17221b01dcab6d9d2cb4424b3314 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 24 Jul 2014 16:07:43 +0100 Subject: [PATCH] Report client side errors to server --- .../coffee/ide/editor/EditorManager.coffee | 5 +++- .../web/public/coffee/ide/services/ide.coffee | 28 ++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/services/web/public/coffee/ide/editor/EditorManager.coffee b/services/web/public/coffee/ide/editor/EditorManager.coffee index 57f4f63091..d190c06be9 100644 --- a/services/web/public/coffee/ide/editor/EditorManager.coffee +++ b/services/web/public/coffee/ide/editor/EditorManager.coffee @@ -50,7 +50,10 @@ define [ @$scope.editor.opening = true @_openNewDocument doc, (error, sharejs_doc) => if error? - @ide.showGenericServerErrorMessage() + @ide.showGenericMessageModal( + "Error opening document" + "Sorry, something went wrong opening this document. Please try again." + ) return @$scope.$broadcast "doc:opened" diff --git a/services/web/public/coffee/ide/services/ide.coffee b/services/web/public/coffee/ide/services/ide.coffee index a0d724dbfd..1410e3db33 100644 --- a/services/web/public/coffee/ide/services/ide.coffee +++ b/services/web/public/coffee/ide/services/ide.coffee @@ -7,14 +7,28 @@ define [ ide = {} ide.$http = $http - ide.pushEvent = () -> - #console.log "PUSHING EVENT STUB", arguments + @recentEvents = [] + ide.pushEvent = (type, meta = {}) => + @recentEvents.push type: type, meta: meta, date: new Date() + if @recentEvents.length > 40 + @recentEvents.shift() - ide.reportError = () -> - console.log "REPORTING ERROR STUB", arguments - - ide.showGenericServerErrorMessage = () -> - console.error "GENERIC SERVER ERROR MESSAGE STUB" + ide.reportError = (error, meta = {}) => + meta.client_id = @socket?.socket?.sessionid + meta.transport = @socket?.socket?.transport?.name + meta.client_now = new Date() + meta.recent_events = @recentEvents + errorObj = {} + if typeof error == "object" + for key in Object.getOwnPropertyNames(error) + errorObj[key] = error[key] + else if typeof error == "string" + errorObj.message = error + $http.post "/error/client", { + error: errorObj + meta: meta + _csrf: window.csrfToken + } ide.showGenericMessageModal = (title, message) -> $modal.open {