Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} catch (err) {
// probably not JSON, could be an HTML response
const titleContent = /<title>(.+?)<\/title>/.exec(body);
errorMessage = titleContent ? titleContent[1] : 'REST API error';
}
logError({
...logBase,
body: body.length > 512 ? `${body.substr(0, 512)}...` : body,
err: new Error(errorMessage),
context: response, // this will provide limited info - check apiRequest for more detail
});
return;
}
// not an error response - log in dev, not prod
if (process.env.NODE_ENV !== 'production') {
logger.info({
...logBase,
httpRequest: response,
});
}
};
</title>
errorMessage = JSON.stringify(info.errors[0]) || body;
} catch (err) {
// probably not JSON, could be an HTML response
const titleContent = /<title>(.+?)<\/title>/.exec(body);
errorMessage = titleContent ? titleContent[1] : 'REST API error';
}
logError({
...logBase,
body: body.length > 512 ? `${body.substr(0, 512)}...` : body,
err: new Error(errorMessage),
context: response, // this will provide limited info - check apiRequest for more detail
});
return;
}
// not an error response
logger.info({
...logBase,
httpRequest: response,
});
};
</title>
export const makeLogResponse = request => ([response, body]) => {
const {
request: { headers, method, uri: { href: url } },
statusCode,
} = response;
const logBase = {
...request.raw, // request to /mu_api
externalRequest: { headers, method, url }, // request to https://api.meetup.com/
};
if (
statusCode >= 500 || // REST API had an internal error
(method.toLowerCase() === 'get' && statusCode >= 400) // something fishy with a GET
) {
const logError = (statusCode < 500 ? logger.warn : logger.error).bind(
logger
);
let errorMessage;
try {
// well-behaved API errors return a JSON object with an `errors` array
const info = JSON.parse(body);
errorMessage = JSON.stringify(info.errors[0]) || body;
} catch (err) {
// probably not JSON, could be an HTML response
const titleContent = /<title>(.+?)<\/title>/.exec(body);
errorMessage = titleContent ? titleContent[1] : 'REST API error';
}
logError({
...logBase,
body: body.length > 512 ? `${body.substr(0, 512)}...` : body,
err: new Error(errorMessage),</title>
},
statusCode,
} = response;
const logBase = {
externalRequest: { headers, method, url }, // request to https://api.meetup.com/
};
if (
statusCode >= 500 || // REST API had an internal error
(method.toLowerCase() === 'get' && statusCode >= 400) // something fishy with a GET
) {
if (isBot(request.headers['user-agent'])) {
// don't log errors from bots - e.g. for deleted groups/events/whatever
return;
}
const logError = (statusCode < 500 ? logger.warn : logger.error).bind(logger);
let errorMessage;
try {
// well-behaved API errors return a JSON object with an `errors` array
const info = JSON.parse(body);
errorMessage = JSON.stringify(info.errors[0]) || body;
} catch (err) {
// probably not JSON, could be an HTML response
const titleContent = /<title>(.+?)<\/title>/.exec(body);
errorMessage = titleContent ? titleContent[1] : 'REST API error';
}
logError({
...logBase,
body: body.length > 512 ? `${body.substr(0, 512)}...` : body,
err: new Error(errorMessage),
context: response, // this will provide limited info - check apiRequest for more detail
});</title>
// @flow
const log = require('mwp-logger-plugin').logger;
const avro = require('avsc');
const uuidv1 = require('uuid/v1');
const AWS = require('aws-sdk');
const canUsePubSub =
process.env.GAE_INSTANCE || process.env.GOOGLE_APPLICATION_CREDENTIALS;
const sts = new AWS.STS();
/*
* There are currently 2 distinct analytics logging methods
* 1. `stdout`: used in dev and compatible with https://github.com/meetup/blt-fluentd
* in k8s-based applications in GCP
* 2. Google Pub/Sub, which is used in GAE and any environment with GOOGLE_APPLICATION_CREDENTIALS
* environment variable set to point toward Google JSON client credentials file
*
* @see https://meetup.atlassian.net/wiki/display/MUP/Analytics+Logging#AnalyticsLogging-Theinputmechanism
function mapStateToProps(state) {
logger.info(state);
return {
data: (state.api.foo || {}).value,
};
}
.catch(err => log.error(err));
};