@netlify/build-info
Advanced tools
Comparing version 7.13.0 to 7.13.1
import { type Client, NotifiableError } from '@bugsnag/js'; | ||
export type Severity = 'info' | 'warning' | 'error'; | ||
/** Report an error to bugsnag */ | ||
export declare function report(error: NotifiableError, options?: { | ||
export declare function report(error: NotifiableError | Record<string, any>, options?: { | ||
context?: string; | ||
@@ -6,0 +6,0 @@ severity?: Severity; |
import bugsnag from '@bugsnag/js'; | ||
const { default: Bugsnag } = bugsnag; | ||
/** Normalize an error to the NotifiableError type */ | ||
const normalizeError = (error) => { | ||
// Already in an acceptable NotifiableError format | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
if (typeof error === 'object' && (error.errorClass || error.name)) { | ||
return error; | ||
} | ||
if (typeof error === 'string') { | ||
// BugSnag suggest sending an Error rather than string to get better stack traces | ||
return new Error(error); | ||
} | ||
// If the error is an object with a message, create a generic Error | ||
if (typeof error === 'object' && error.message) { | ||
return new Error(error.message); | ||
} | ||
// If the error format is unexpected, create a generic Error | ||
return new Error(`Unexpected error format: ${JSON.stringify(error)}`); | ||
}; | ||
/** Report an error to bugsnag */ | ||
export function report(error, options = {}) { | ||
; | ||
(options.client || Bugsnag).notify(error, (event) => { | ||
const normalizedError = normalizeError(error); | ||
const client = options.client || Bugsnag; | ||
client.notify(normalizedError, (event) => { | ||
for (const [section, values] of Object.entries(options.metadata || {})) { | ||
event.addMetadata(section, values); | ||
} | ||
// If the error is an object with a documentation_url property, it's probably a GitHub API error | ||
if (typeof error === 'object' && 'documentation_url' in error) { | ||
event.addMetadata('Documentation URL', error.documentation_url); | ||
} | ||
event.context = options.context; | ||
event.severity = options.severity || 'error'; | ||
@@ -11,0 +37,0 @@ event.context = options.context; |
{ | ||
"name": "@netlify/build-info", | ||
"version": "7.13.0", | ||
"version": "7.13.1", | ||
"description": "Build info utility", | ||
@@ -76,3 +76,3 @@ "type": "module", | ||
}, | ||
"gitHead": "f04cc67a1ebb8ca419e85271a43d28680aaa9896" | ||
"gitHead": "664052bb513e410827e859e9d2f1e72538ddbf09" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
319395
5852