Skip to content

Commit

Permalink
Merge pull request #429 from rollbar/react-native
Browse files Browse the repository at this point in the history
beginning of react native support
  • Loading branch information
rokob authored Oct 31, 2017
2 parents ce3e5ac + 29524f7 commit 218ac44
Show file tree
Hide file tree
Showing 12 changed files with 613 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ Default: ```"error"```
</dt>
<dd>The url to which items get POSTed. This is mostly relevant to our enterprise customers. You will, however, need this if you're proxying the requests through your own server, or you're an enterprise customer.

Default: ```'https://api.rollbar.com/api/1/'```
Default: ```'https://api.rollbar.com/api/1/item'```
</dd>

<dt>autoInstrument
Expand Down Expand Up @@ -1159,7 +1159,7 @@ Other options can be passed into the constructor as a collection. E.g.:
new Rollbar({
accessToken: "POST_SERVER_ITEM_ACCESS_TOKEN",
environment: "staging",
endpoint: "https://api.rollbar.com/api/1/"
endpoint: "https://api.rollbar.com/api/1/item"
});
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"host": "cdnjs.cloudflare.com"
},
"defaults": {
"endpoint": "api.rollbar.com/api/1/",
"endpoint": "api.rollbar.com/api/1/item/",
"browser": {
"scrubFields": [
"pw",
Expand Down
6 changes: 3 additions & 3 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var helpers = require('./apiUtility');

var defaultOptions = {
hostname: 'api.rollbar.com',
path: '/api/1',
path: '/api/1/item/',
search: null,
version: '1',
protocol: 'https:',
Expand All @@ -21,7 +21,7 @@ var defaultOptions = {
* accessToken: the accessToken to use for posting items to rollbar
* endpoint: an alternative endpoint to send errors to
* must be a valid, fully qualified URL.
* The default is: https://api.rollbar.com/api/1
* The default is: https://api.rollbar.com/api/1/item
* proxy: if you wish to proxy requests provide an object
* with the following keys:
* host or hostname (required): foo.example.com
Expand All @@ -44,7 +44,7 @@ function Api(options, t, u, j) {
* @param callback
*/
Api.prototype.postItem = function(data, callback) {
var transportOptions = helpers.transportOptions(this.transportOptions, '/item/', 'POST');
var transportOptions = helpers.transportOptions(this.transportOptions, 'POST');
var payload = helpers.buildPayload(this.accessToken, data, this.jsonBackup);
this.transport.post(this.accessToken, transportOptions, payload, callback);
};
Expand Down
4 changes: 2 additions & 2 deletions src/apiUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ function getTransportFromOptions(options, defaults, url) {
};
}

function transportOptions(transport, path, method) {
function transportOptions(transport, method) {
var protocol = transport.protocol || 'https:';
var port = transport.port || (protocol === 'http:' ? 80 : protocol === 'https:' ? 443 : undefined);
var hostname = transport.hostname;
path = appendPathToPath(transport.path, path);
var path = transport.path;
if (transport.search) {
path = path + transport.search;
}
Expand Down
4 changes: 4 additions & 0 deletions src/rateLimiter.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ RateLimiter.prototype.shouldSend = function(item, now) {
this.perMinCounter++;

var shouldSend = !checkRate(item, globalRateLimit, this.counter);
shouldSend = shouldSend && !checkRate(item, globalRateLimitPerMin, this.perMinCounter);
return shouldSendValue(this.platform, this.platformOptions, null, shouldSend, globalRateLimit);
};

Expand Down Expand Up @@ -121,6 +122,9 @@ function rateLimitPayload(platform, options, globalRateLimit) {
} else if (platform === 'server') {
item.framework = options.framework || 'node-js';
item.notifier.name = options.notifier.name;
} else if (platform === 'react-native') {
item.framework = options.framework || 'react-native';
item.notifier.name = options.notifier.name;
}
return item;
}
Expand Down
11 changes: 11 additions & 0 deletions src/react-native/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

/* eslint-disable no-console */
var logger = {
error: console.error.bind(console),
info: console.info.bind(console),
log: console.log.bind(console)
};
/* eslint-enable no-console */

module.exports = logger;
37 changes: 37 additions & 0 deletions src/react-native/predicates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var _ = require('../utility');
var logger = require('./logger');

function checkLevel(item, settings) {
var level = item.level || 'error';
var reportLevel = settings.reportLevel;

var levelVal = _.LEVELS[level] || 0;
var reportLevelVal = _.LEVELS[reportLevel] || 0;

if (levelVal < reportLevelVal) {
return false;
}
return true;
}

function userCheckIgnore(item, settings) {
var isUncaught = !!item._isUncaught;
delete item._isUncaught;
var args = item._originalArgs;
delete item._originalArgs;
try {
if (_.isFunction(settings.checkIgnore) && settings.checkIgnore(isUncaught, args, item)) {
return false;
}
} catch (e) {
settings.checkIgnore = null;
logger.error('Error while calling custom checkIgnore(), removing', e);
}
return true;
}

module.exports = {
checkLevel: checkLevel,
userCheckIgnore: userCheckIgnore
};

Loading

0 comments on commit 218ac44

Please sign in to comment.