feat: enhance error log

This commit is contained in:
EnixCoda 2019-09-22 22:55:11 +08:00
parent 1514c3e7fe
commit baa41b3084
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD
3 changed files with 10 additions and 5 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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)
}
}