Adjust docs & parameters toto fit the API
Signed-off-by: Philipp Hugenroth <philipph@spotify.com>
This commit is contained in:
@@ -71,8 +71,11 @@ For example, this is the default `ApiFactory` for the `ErrorApi`:
|
||||
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, { hidden: false });
|
||||
return errorApi;
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ErrorApi } from '@backstage/core-plugin-api';
|
||||
import { ErrorApi, ErrorContext } from '@backstage/core-plugin-api';
|
||||
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
@@ -15,12 +15,16 @@ import { ErrorApi } from '@backstage/core-plugin-api';
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export class UnhandledErrorForwarder {
|
||||
static forward(errorApi: ErrorApi, hidden = false) {
|
||||
/**
|
||||
* Add event listener, such that unhandled errors can be forwarded using an given `ErrorApi` instance
|
||||
*/
|
||||
static forward(errorApi: ErrorApi, errorContext: ErrorContext) {
|
||||
window.addEventListener(
|
||||
'unhandledrejection',
|
||||
(e: PromiseRejectionEvent) => {
|
||||
errorApi.post(e.reason as Error, { hidden });
|
||||
errorApi.post(e.reason as Error, errorContext);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ export const defaultApis = [
|
||||
deps: { alertApi: alertApiRef },
|
||||
factory: ({ alertApi }) => {
|
||||
const errorApi = new ErrorAlerter(alertApi, new ErrorApiForwarder());
|
||||
UnhandledErrorForwarder.forward(errorApi);
|
||||
UnhandledErrorForwarder.forward(errorApi, { hidden: false });
|
||||
return errorApi;
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user