<commit_before>#!/usr/bin/env node

'use strict';

var argv = require('optimist')
  .usage('$0 access_token src_space_id dest_space_id')
  .demand(3)
  .argv;
var Promise = require('bluebird');
var contentful = require('../index');
var accessToken = argv._[0];
var srcSpaceId = argv._[1];
var destSpaceId = argv._[2];

var client = contentful.createClient({
  accessToken: accessToken
});

var log = console.log.bind(log);

Promise.all([
  client.getSpace(srcSpaceId).catch(function() {
    console.log('Could not find source Space %s using access token %s', srcSpaceId, accessToken);
    return Promise.rejected();
  }),
  client.getSpace(destSpaceId).catch(function() {
    console.log('Could not find destination Space %s using access token %s', destSpaceId, accessToken);
    return Promise.rejected();
  })
]).spread(function(srcSpace, destSpace) {
  srcSpace.getContentTypes().map(function(contentType) {
    destSpace.createContentType(contentType).then(function() {
      console.log('Duplicated Content Type %s from %s to %s',
                  contentType.sys.id, srcSpaceId, destSpaceId);
    }).catch(function(error) {
      var errorType = JSON.parse(error.body).sys.id;
      return errorType === 'VersionMismatch';
    }, function() {
      console.log('Content Type %s already exists in %s', contentType.sys.id, destSpaceId);
    }).catch(function(error) {
      console.log('Could not duplicate Content Type %s from %s to %s',
                  contentType.sys.id, srcSpaceId, destSpaceId);
      throw error;
    });
  });
});<commit_msg>Return error in purely-informative rejection handlers<commit_after>#!/usr/bin/env node

'use strict';

var argv = require('optimist')
  .usage('$0 access_token src_space_id dest_space_id')
  .demand(3)
  .argv;
var Promise = require('bluebird');
var contentful = require('../index');
var accessToken = argv._[0];
var srcSpaceId = argv._[1];
var destSpaceId = argv._[2];

var client = contentful.createClient({
  accessToken: accessToken
});

var log = console.log.bind(log);

Promise.all([
  client.getSpace(srcSpaceId).catch(function(error) {
    console.log('Could not find source Space %s using access token %s', srcSpaceId, accessToken);
    return error;
  }),
  client.getSpace(destSpaceId).catch(function(error) {
    console.log('Could not find destination Space %s using access token %s', destSpaceId, accessToken);
    return error;
  })
]).spread(function(srcSpace, destSpace) {
  srcSpace.getContentTypes().map(function(contentType) {
    destSpace.createContentType(contentType).then(function() {
      console.log('Duplicated Content Type %s from %s to %s',
                  contentType.sys.id, srcSpaceId, destSpaceId);
    }).catch(function(error) {
      var errorType = JSON.parse(error.body).sys.id;
      return errorType === 'VersionMismatch';
    }, function() {
      console.log('Content Type %s already exists in %s', contentType.sys.id, destSpaceId);
    }).catch(function(error) {
      console.log('Could not duplicate Content Type %s from %s to %s',
                  contentType.sys.id, srcSpaceId, destSpaceId);
      return error;
    });
  });
});
{'fraction_non_alphanumeric': 0.14504303474657315, 'fraction_numerical': 0.0031877590054191903, 'mean_word_length': 3.926216640502355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3198677', 'n_tokens_mistral': 974, 'n_tokens_neox': 960, 'n_words': 235}