code: function(defaultMessage, err) {
    var errorObject;
    if (typeof err.error === 'object' && typeof err.error.message === 'string') {
      // Web API Error format
      errorObject = new WebApiError(err.error.message, err.error.status);
    } else if (typeof err.error === 'string') {
      // Authorization Error format
      /* jshint ignore:start */
      errorObject = new WebApiError(err.error + ': ' + err['error_description']);
      /* jshint ignore:end */
    } else if (typeof err === 'string') {
      // Serialized JSON error
      try {
        var parsedError = JSON.parse(err);
        errorObject = new WebApiError(
          parsedError.error.message,
          parsedError.error.status
        );
      } catch (err) {
        // Error not JSON formatted
      }
    }
  
    if (!errorObject) {
      // Unexpected format
      errorObject = new WebApiError(defaultMessage + ': ' + JSON.stringify(err));
    }
  
    return errorObject;
  }
docs: /* Create an error object from an error returned from the Web API