Feat: News in the client app (#34392)
This commit is contained in:
@ -8,47 +8,10 @@ import { unwrapHandledError } from '../utils/create-handled-error.js';
|
||||
|
||||
const isDev = process.env.NODE_ENV !== 'production';
|
||||
|
||||
// const toString = Object.prototype.toString;
|
||||
// is full error or just trace
|
||||
// _.toString(new Error('foo')) => "Error: foo
|
||||
// Object.prototype.toString.call(new Error('foo')) => "[object Error]"
|
||||
// const isInspect = val => !val.stack && _.toString(val) === toString.call(val);
|
||||
// const stringifyErr = val => {
|
||||
// if (val.stack) {
|
||||
// return String(val.stack);
|
||||
// }
|
||||
|
||||
// const str = String(val);
|
||||
|
||||
// return isInspect(val) ?
|
||||
// inspect(val) :
|
||||
// str;
|
||||
// };
|
||||
|
||||
// const createStackHtml = _.flow(
|
||||
// _.cond([
|
||||
// [isInspect, err => [err]],
|
||||
// // may be stack or just err.msg
|
||||
// [_.stubTrue, _.flow(stringifyErr, _.split('\n'), _.tail) ]
|
||||
// ]),
|
||||
// _.map(_.escape),
|
||||
// _.map(line => `<li>${line}</lin>`),
|
||||
// _.join('')
|
||||
// );
|
||||
|
||||
// const createErrorTitle = _.cond([
|
||||
// [
|
||||
// _.negate(isInspect),
|
||||
// _.flow(stringifyErr, _.split('\n'), _.head, _.defaultTo('Error'))
|
||||
// ],
|
||||
// [_.stubTrue, _.constant('Error')]
|
||||
// ]);
|
||||
|
||||
export default function prodErrorHandler() {
|
||||
// error handling in production.
|
||||
// disabling eslint due to express parity rules for error handlers
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
return function(err, req, res, next) {
|
||||
// eslint-disable-line
|
||||
const handled = unwrapHandledError(err);
|
||||
// respect handled error status
|
||||
let status = handled.status || err.status || res.statusCode;
|
||||
|
@ -5,20 +5,30 @@ import {
|
||||
unwrapHandledError
|
||||
} from '../utils/create-handled-error.js';
|
||||
|
||||
const { ROLLBAR_APP_ID } = process.env;
|
||||
import { rollbar } from '../../../config/secrets';
|
||||
|
||||
const rollbar = new Rollbar(ROLLBAR_APP_ID);
|
||||
const { appId } = rollbar;
|
||||
const reporter = new Rollbar(appId);
|
||||
const log = debug('fcc:middlewares:error-reporter');
|
||||
|
||||
const errTemplate = ({message, ...restError}, req) => `
|
||||
const errTemplate = (error, req) => {
|
||||
const { message, stack } = error;
|
||||
return `
|
||||
Time: ${new Date(Date.now()).toISOString()}
|
||||
Error: ${message}
|
||||
Is authenticated user: ${!!req.user}
|
||||
Route: ${JSON.stringify(req.route, null, 2)}
|
||||
Stack: ${stack}
|
||||
|
||||
${JSON.stringify(restError, null, 2)}
|
||||
// raw
|
||||
${JSON.stringify(error, null, 2)}
|
||||
|
||||
`;
|
||||
};
|
||||
|
||||
export function reportError(err) {
|
||||
return reporter.error(err.message, err);
|
||||
}
|
||||
|
||||
export default function errrorReporter() {
|
||||
if (process.env.NODE_ENV !== 'production' && process.env.ERROR_REPORTER) {
|
||||
@ -44,6 +54,7 @@ export default function errrorReporter() {
|
||||
// logging the error provides us with more information,
|
||||
// i.e isAuthenticatedUser, req.route
|
||||
console.error(errTemplate(err, req));
|
||||
return rollbar.error(err.message, err);
|
||||
reportError(err);
|
||||
return next(err);
|
||||
};
|
||||
}
|
||||
|
@ -6,9 +6,17 @@ import { homeLocation } from '../../../config/env';
|
||||
|
||||
import { wrapHandledError } from '../utils/create-handled-error';
|
||||
|
||||
// We need to tunnel through a proxy path set up within
|
||||
// the gatsby app, at this time, that path is /internal
|
||||
const whiteListRE = new RegExp([
|
||||
'^/internal/n/',
|
||||
'^/internal/p\??'
|
||||
].join('|'));
|
||||
|
||||
|
||||
export default () => function authorizeByJWT(req, res, next) {
|
||||
const path = req.path.split('/')[1];
|
||||
if (/^external$|^internal$/.test(path)) {
|
||||
if (/^external$|^internal$/.test(path) && !whiteListRE.test(req.path)) {
|
||||
const cookie = req.signedCookies && req.signedCookies['jwt_access_token'] ||
|
||||
req.cookie && req.cookie['jwt_access_token'];
|
||||
if (!cookie) {
|
||||
|
Reference in New Issue
Block a user