import Ember from "ember";
import config from "../config/environment";

export default Ember.Service.extend({
  session: Ember.inject.service(),

  error: function(reason) {
    if (reason.status === 0) {
      return;
    }
    console.info(reason);
    if (config.environment === "production" || config.staging) {
      var userName = this.get("session.currentUser.fullName");
      var userId = this.get("session.currentUser.id");
      var error = reason instanceof Error || typeof reason != "object" ?
          reason : JSON.stringify(reason);

      var airbrake = new airbrakeJs.Client();
      airbrake.setHost(config.APP.AIRBRAKE_HOST);
      airbrake.setProject(config.APP.AIRBRAKE_PROJECT_ID, config.APP.AIRBRAKE_PROJECT_KEY);
      airbrake.setEnvironmentName(config.staging ? "staging" : config.environment);

      airbrake.push({
        error: error,
        context: { userId: userId, userName: userName }
      });
    }
  }
});

@@ -543,17 +543,16 @@
 eason);%0A
-%0A
       va
@@ -557,50 +557,77 @@
 var 
-airbrake = new airbrakeJs.Cli
+environment = config.staging ? %22staging%22 : config.environm
 ent
-()
 ;%0A      
 airb
@@ -626,66 +626,96 @@
     
-airbrake.setHost(config.APP.AIRBRAKE_HOST)
+var version = %60$%7Bconfig.APP.SHA%7D (shared $%7Bconfig.APP.SHARED_SHA%7D)%60
 ;%0A
+%0A
       
+var 
 airbrake
 .set
@@ -714,20 +714,54 @@
 rake
-.setP
+ = new airbrakeJs.Client(%7B%0A        p
 roject
-(
+Id: 
 conf
@@ -787,16 +787,36 @@
 JECT_ID,
+%0A        projectKey:
  config.
@@ -839,16 +839,24 @@
 JECT_KEY
+%0A      %7D
 );%0A     
@@ -872,75 +872,40 @@
 .set
-EnvironmentName(config.staging ? %22staging%22 : config.environment
+Host(config.APP.AIRBRAKE_HOST
 );%0A
-%0A
     
@@ -919,44 +919,23 @@
 ake.
-push(%7B%0A        error: error,%0A       
+notify(%7B error,
  con
@@ -945,16 +945,8 @@
 t: %7B
- userId:
  use
@@ -962,26 +962,32 @@
 Name
-: userName %7D%0A     
+, environment, version %7D
  %7D);

Update errbit calls to use non-deprecated methods, and add app version