Adjust UnhandledErrorForwarder to not silence error

- Changes related to revew

Signed-off-by: Philipp Hugenroth <philipph@spotify.com>
This commit is contained in:
Philipp Hugenroth
2021-06-18 16:53:39 +02:00
parent 8999203add
commit 11ff8c952a
6 changed files with 12 additions and 22 deletions
+1 -1
View File
@@ -3,4 +3,4 @@
'@backstage/core-api': patch
---
Catch unhandled promise rejections & forward them to the ErrorApi to align with general error handling
Introducing new UnhandledErrorForwarder installed by default. For catchin unhandled promise rejections you can override the API to align with general error handling.
@@ -16,4 +16,3 @@
export { ErrorAlerter } from './ErrorAlerter';
export { ErrorApiForwarder } from './ErrorApiForwarder';
export { UnhandledErrorForwarder } from './UnhandledErrorForwarder';
@@ -16,21 +16,11 @@ import { ErrorApi } from '../../definitions';
* limitations under the License.
*/
export class UnhandledErrorForwarder {
static forward(errorApi: ErrorApi) {
static forward(errorApi: ErrorApi, hidden = false) {
window.addEventListener(
'unhandledrejection',
(e: PromiseRejectionEvent) => {
errorApi.post(
{
name: `Unhandled Rejection: ${e.reason.message}`,
message: e.reason.message,
stack: e.reason.stack,
},
{ hidden: true },
);
// eslint-disable-next-line no-console
console.error(e.reason);
e.preventDefault();
errorApi.post(e.reason as Error, { hidden });
},
);
}
@@ -16,3 +16,4 @@
export { ErrorAlerter } from './ErrorAlerter';
export { ErrorApiForwarder } from './ErrorApiForwarder';
export { UnhandledErrorForwarder } from './UnhandledErrorForwarder';
+6 -2
View File
@@ -30,6 +30,7 @@ import {
UrlPatternDiscovery,
SamlAuth,
OneLoginAuth,
UnhandledErrorForwarder,
} from '../apis';
import {
@@ -67,8 +68,11 @@ export const defaultApis = [
createApiFactory({
api: errorApiRef,
deps: { alertApi: alertApiRef },
factory: ({ alertApi }) =>
new ErrorAlerter(alertApi, new ErrorApiForwarder()),
factory: ({ alertApi }) => {
const errorApi = new ErrorAlerter(alertApi, new ErrorApiForwarder());
UnhandledErrorForwarder.forward(errorApi);
return errorApi;
},
}),
createApiFactory({
api: storageApiRef,
@@ -47,7 +47,6 @@ import {
oneloginAuthApiRef,
OneLoginAuth,
oidcAuthApiRef,
UnhandledErrorForwarder,
} from '@backstage/core-api';
import OAuth2Icon from '@material-ui/icons/AcUnit';
@@ -65,11 +64,8 @@ export const defaultApis = [
createApiFactory({
api: errorApiRef,
deps: { alertApi: alertApiRef },
factory: ({ alertApi }) => {
const errorApi = new ErrorAlerter(alertApi, new ErrorApiForwarder());
UnhandledErrorForwarder.forward(errorApi);
return errorApi;
},
factory: ({ alertApi }) =>
new ErrorAlerter(alertApi, new ErrorApiForwarder()),
}),
createApiFactory({
api: storageApiRef,