mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
36 lines
761 B
JavaScript
36 lines
761 B
JavaScript
import { version } from '../package'
|
|
// TODO: set this through ENV or something else
|
|
const LOG_ENDPOINT = 'https://enix.one/gitako/log'
|
|
|
|
export function raiseError(error) {
|
|
return reportError(error)
|
|
}
|
|
|
|
export function withErrorLog(method, args) {
|
|
return [
|
|
function() {
|
|
try {
|
|
method.apply(this, arguments)
|
|
} catch (error) {
|
|
raiseError(error)
|
|
}
|
|
},
|
|
args,
|
|
]
|
|
}
|
|
|
|
function encodeParams(params) {
|
|
return Object.keys(params)
|
|
.map(key => `${key}=${encodeURIComponent(JSON.stringify(params[key]))}`)
|
|
.join('&')
|
|
}
|
|
|
|
function reportError(error) {
|
|
return fetch(
|
|
`${LOG_ENDPOINT}?${encodeParams({
|
|
error: (error && error.message) || error,
|
|
path: window.location.href,
|
|
version,
|
|
})}`
|
|
)
|
|
}
|