Add UnhandledErrorForwarder forwarding errors to ErrorApi
Signed-off-by: Philipp Hugenroth <philipph@spotify.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { ErrorApi } from '../../definitions';
|
||||
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export class UnhandledErrorForwarder {
|
||||
static forward(errorApi: ErrorApi) {
|
||||
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();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -16,3 +16,4 @@
|
||||
|
||||
export { ErrorAlerter } from './ErrorAlerter';
|
||||
export { ErrorApiForwarder } from './ErrorApiForwarder';
|
||||
export { UnhandledErrorForwarder } from './UnhandledErrorForwarder';
|
||||
|
||||
@@ -47,6 +47,7 @@ import {
|
||||
oneloginAuthApiRef,
|
||||
OneLoginAuth,
|
||||
oidcAuthApiRef,
|
||||
UnhandledErrorForwarder,
|
||||
} from '@backstage/core-api';
|
||||
|
||||
import OAuth2Icon from '@material-ui/icons/AcUnit';
|
||||
@@ -64,8 +65,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,
|
||||
|
||||
Reference in New Issue
Block a user