<commit_before>import Ember from 'ember';

export default Ember.Route.extend({
  beforeModel () {
    return this.session.fetch('github-oauth2').catch(function() {
      // Swallow error for now
    });
  },

  actions: {
    saveGist (gist) {
      var newGist = gist.get('isNew');
      gist.save().then(() => {
        this.notify.info('Saved to Gist %@ on Github'.fmt(gist.get('id')));
        if(newGist) {
          this.transitionTo('gist.edit', gist).then(function() {
            this.send('setSaved');
          });
        } else {
          this.send('setSaved');
        }
      });
    },

    setSaved () {
      this.get('controller').set('unsaved', false);
    },

    fork (gist) {
      gist.fork().then((response) => {
        let id = response.id;
        let newGist = this.duplicate(gist);
        return newGist.save().then(() => {
          this.transitionTo('gist.edit', id);
        });
      }).catch((error) => {
        if (error && error.errors) {
          let firstError = error.errors[0];
          if (firstError.code === "unprocessable" && firstError.field === "forks") {
            this.notify.info("You already own this gist.");
          }
        }
      });
    },

    signInViaGithub () {
      this.session.open('github-oauth2').catch(function(error) {
        alert('Could not sign you in: ' + error.message);
        throw error;
      });
    },

    signOut () {
      this.session.close();
    }
  },

  duplicate(gist) {
    var newGistJson = gist.toJSON();
    Object.keys(newGistJson).forEach((key) => {
      if (newGistJson[key] !== gist.get(key)) {
        newGistJson[key] = gist.get(key);
      }
    });
    newGistJson.id = undefined;
    var newGist = this.get('store').createRecord('gist', newGistJson);
    gist.get('files').currentState.forEach((file) => {
      file.record.set('gist', newGist);
    });
    return newGist;
  }
});<commit_msg>Rethrow error if not the one we understood<commit_after>import Ember from 'ember';

export default Ember.Route.extend({
  beforeModel () {
    return this.session.fetch('github-oauth2').catch(function() {
      // Swallow error for now
    });
  },

  actions: {
    saveGist (gist) {
      var newGist = gist.get('isNew');
      gist.save().then(() => {
        this.notify.info('Saved to Gist %@ on Github'.fmt(gist.get('id')));
        if(newGist) {
          this.transitionTo('gist.edit', gist).then(function() {
            this.send('setSaved');
          });
        } else {
          this.send('setSaved');
        }
      });
    },

    setSaved () {
      this.get('controller').set('unsaved', false);
    },

    fork (gist) {
      gist.fork().then((response) => {
        let id = response.id;
        let newGist = this.duplicate(gist);
        return newGist.save().then(() => {
          this.transitionTo('gist.edit', id);
        });
      }).catch((error) => {
        if (error && error.errors) {
          let firstError = error.errors[0];
          if (firstError.code === "unprocessable" && firstError.field === "forks") {
            this.notify.info("You already own this gist.");
            return;
          }
        }
        throw error;
      });
    },

    signInViaGithub () {
      this.session.open('github-oauth2').catch(function(error) {
        alert('Could not sign you in: ' + error.message);
        throw error;
      });
    },

    signOut () {
      this.session.close();
    }
  },

  duplicate(gist) {
    var newGistJson = gist.toJSON();
    Object.keys(newGistJson).forEach((key) => {
      if (newGistJson[key] !== gist.get(key)) {
        newGistJson[key] = gist.get(key);
      }
    });
    newGistJson.id = undefined;
    var newGist = this.get('store').createRecord('gist', newGistJson);
    gist.get('files').currentState.forEach((file) => {
      file.record.set('gist', newGist);
    });
    return newGist;
  }
});
{'fraction_non_alphanumeric': 0.17807514153371076, 'fraction_numerical': 0.001544004117344313, 'mean_word_length': 2.1220883534136545, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4846518', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1278, 'n_words': 206}