Adjust docs & parameters toto fit the API

Signed-off-by: Philipp Hugenroth <philipph@spotify.com>
This commit is contained in:
Philipp Hugenroth
2021-06-22 12:57:08 +02:00
parent 9f8a078640
commit de77f03f01
3 changed files with 13 additions and 6 deletions
+5 -2
View File
@@ -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);
},
);
}
+1 -1
View File
@@ -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;
},
}),