Skip to content

Commit

Permalink
fix(hydrate): improve dev server console error
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Sep 18, 2020
1 parent 51081b8 commit 9cb31a5
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/hydrate/runner/runtime-log.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
import type * as d from '../../declarations';
import { renderCatchError, renderBuildDiagnostic } from './render-utils';

export function runtimeLogging(win: Window & typeof globalThis, opts: d.HydrateDocumentOptions, results: d.HydrateResults) {
export function runtimeLogging(
win: Window & typeof globalThis,
opts: d.HydrateDocumentOptions,
results: d.HydrateResults,
) {
try {
const pathname = win.location.pathname;

win.console.error = (...msgs: any[]) => {
renderCatchError(results, [...msgs].join(', '));
if (opts.runtimeLogging) {
runtimeLog(pathname, 'error', msgs);
const errMsg = msgs
.reduce<string>((errMsg, m) => {
if (m) {
if (m.stack != null) {
return errMsg + ' ' + String(m.stack);
} else {
if (m.message != null) {
return errMsg + ' ' + String(m.message);
}
}
}
return String(m);
}, '')
.trim();

if (errMsg !== '') {
renderCatchError(results, errMsg);

if (opts.runtimeLogging) {
runtimeLog(pathname, 'error', [errMsg]);
}
}
};

Expand Down

0 comments on commit 9cb31a5

Please sign in to comment.