From baa41b3084e2f5553937e0f6f3f8bdaa217b2cf4 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Sun, 22 Sep 2019 22:55:11 +0800 Subject: [PATCH] feat: enhance error log --- src/analytics.ts | 9 +++++++-- src/driver/core/FileExplorer.ts | 2 +- src/utils/GitHubHelper.ts | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/analytics.ts b/src/analytics.ts index dd133c7..40803c5 100644 --- a/src/analytics.ts +++ b/src/analytics.ts @@ -1,6 +1,6 @@ +import * as Sentry from '@sentry/browser' import { Middleware } from 'driver/connect.js' import { IN_PRODUCTION_MODE } from 'env' -import * as Sentry from '@sentry/browser' import { version } from '../package.json' const PUBLIC_KEY = 'd22ec5c9cc874539a51c78388c12e3b0' @@ -29,7 +29,12 @@ export const withErrorLog: Middleware = function withErrorLog(method, args) { ] } -function reportError(error: Error, extra?: any) { +function reportError( + error: Error, + extra?: { + [key: string]: any + }, +) { if (!IN_PRODUCTION_MODE) { console.error(error) console.error('Extra:\n', extra) diff --git a/src/driver/core/FileExplorer.ts b/src/driver/core/FileExplorer.ts index 39c329c..36d7832 100644 --- a/src/driver/core/FileExplorer.ts +++ b/src/driver/core/FileExplorer.ts @@ -118,7 +118,7 @@ function handleParsed(root: TreeNode, parsed: Parsed) { node.accessDenied = true } } else { - raiseError(Error(`Sub-module node ${path} not found`)) + raiseError(new Error(`Sub-module node not found`), { path }) } } else { handleParsed(root, value as Parsed) diff --git a/src/utils/GitHubHelper.ts b/src/utils/GitHubHelper.ts index 761226f..42cbf54 100644 --- a/src/utils/GitHubHelper.ts +++ b/src/utils/GitHubHelper.ts @@ -16,7 +16,7 @@ function isEmptyProject(content: any /* examined any */) { } function isBlockedProject(content: any /* examined any */) { - return content && content['message'] === "Repository access blocked" + return content && content['message'] === 'Repository access blocked' } type Options = { @@ -45,7 +45,7 @@ async function request(url: string, { accessToken }: Options = {}) { if (isEmptyProject(content)) throw new Error(EMPTY_PROJECT) if (isBlockedProject(content)) throw new Error(BLOCKED_PROJECT) // Unknown type of error, report it! - raiseError(new Error(`Got ${res.statusText} when requesting ${url}`)) + raiseError(new Error(res.statusText)) throw new Error(content && content.message) } }