Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save matsimitsu/65f95166ef8b0192e889159172e993cc to your computer and use it in GitHub Desktop.
Save matsimitsu/65f95166ef8b0192e889159172e993cc to your computer and use it in GitHub Desktop.
class @Appsignal
constructor: ->
@action = ""
@tags = {}
set_action: (action) ->
@action = action
tag_request: (tags) ->
for key in tags
@tags[key] = tags[key]
sendError: (error) ->
data = {
action: @action
message: error.message
name: error.name
backtrace: error.stack.split("\n")
path: window.location.pathname
tags: @tags
environment: {
agent: navigator.userAgent
platform: navigator.platform
vendor: navigator.vendor
screen_width: screen.width
screen_height: screen.height
}
}
xhr = new XMLHttpRequest()
xhr.open('POST', '/appsignal_error_catcher', true)
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8')
xhr.send(JSON.stringify(data))
appsignal = new Appsignal
window.appsignal = appsignal
window.onerror = (message, filename, lineno, colno, error) ->
appsignal.sendError(error) if error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment