core-app-api,test-utils: migrated to using new ErrorApi* names
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/core-app-api': patch
|
||||
'@backstage/test-utils': patch
|
||||
---
|
||||
|
||||
Migrated to using new `ErrorApiError` and `ErrorApiErrorContext` names.
|
||||
@@ -199,7 +199,7 @@ export a class that `implements` the target API, for example:
|
||||
|
||||
```ts
|
||||
export class IgnoringErrorApi implements ErrorApi {
|
||||
post(error: Error, context?: ErrorContext) {
|
||||
post(error: ErrorApiError, context?: ErrorApiErrorContext) {
|
||||
// ignore error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import { DiscoveryApi } from '@backstage/core-plugin-api';
|
||||
import { ErrorApi } from '@backstage/core-plugin-api';
|
||||
import { ErrorApiError } from '@backstage/core-plugin-api';
|
||||
import { ErrorApiErrorContext } from '@backstage/core-plugin-api';
|
||||
import { ErrorContext } from '@backstage/core-plugin-api';
|
||||
import { ExternalRouteRef } from '@backstage/core-plugin-api';
|
||||
import { FeatureFlag } from '@backstage/core-plugin-api';
|
||||
import { FeatureFlagsApi } from '@backstage/core-plugin-api';
|
||||
@@ -332,7 +331,7 @@ export class ErrorAlerter implements ErrorApi {
|
||||
context?: ErrorApiErrorContext | undefined;
|
||||
}>;
|
||||
// (undocumented)
|
||||
post(error: Error, context?: ErrorContext): void;
|
||||
post(error: ErrorApiError, context?: ErrorApiErrorContext): void;
|
||||
}
|
||||
|
||||
// @public
|
||||
@@ -340,10 +339,10 @@ export class ErrorApiForwarder implements ErrorApi {
|
||||
// (undocumented)
|
||||
error$(): Observable<{
|
||||
error: Error;
|
||||
context?: ErrorContext;
|
||||
context?: ErrorApiErrorContext;
|
||||
}>;
|
||||
// (undocumented)
|
||||
post(error: Error, context?: ErrorContext): void;
|
||||
post(error: ErrorApiError, context?: ErrorApiErrorContext): void;
|
||||
}
|
||||
|
||||
// @public
|
||||
@@ -604,7 +603,7 @@ export type SignInResult = {
|
||||
|
||||
// @public
|
||||
export class UnhandledErrorForwarder {
|
||||
static forward(errorApi: ErrorApi, errorContext: ErrorContext): void;
|
||||
static forward(errorApi: ErrorApi, errorContext: ErrorApiErrorContext): void;
|
||||
}
|
||||
|
||||
// @public
|
||||
|
||||
@@ -13,7 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { ErrorApi, ErrorContext, AlertApi } from '@backstage/core-plugin-api';
|
||||
import {
|
||||
ErrorApi,
|
||||
ErrorApiError,
|
||||
ErrorApiErrorContext,
|
||||
AlertApi,
|
||||
} from '@backstage/core-plugin-api';
|
||||
|
||||
/**
|
||||
* Decorates an ErrorApi by also forwarding error messages
|
||||
@@ -27,7 +32,7 @@ export class ErrorAlerter implements ErrorApi {
|
||||
private readonly errorApi: ErrorApi,
|
||||
) {}
|
||||
|
||||
post(error: Error, context?: ErrorContext) {
|
||||
post(error: ErrorApiError, context?: ErrorApiErrorContext) {
|
||||
if (!context?.hidden) {
|
||||
this.alertApi.post({ message: error.message, severity: 'error' });
|
||||
}
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ErrorApi, ErrorContext } from '@backstage/core-plugin-api';
|
||||
import {
|
||||
ErrorApi,
|
||||
ErrorApiError,
|
||||
ErrorApiErrorContext,
|
||||
} from '@backstage/core-plugin-api';
|
||||
import { Observable } from '@backstage/types';
|
||||
import { PublishSubject } from '../../../lib/subjects';
|
||||
|
||||
@@ -26,14 +30,14 @@ import { PublishSubject } from '../../../lib/subjects';
|
||||
export class ErrorApiForwarder implements ErrorApi {
|
||||
private readonly subject = new PublishSubject<{
|
||||
error: Error;
|
||||
context?: ErrorContext;
|
||||
context?: ErrorApiErrorContext;
|
||||
}>();
|
||||
|
||||
post(error: Error, context?: ErrorContext) {
|
||||
post(error: ErrorApiError, context?: ErrorApiErrorContext) {
|
||||
this.subject.next({ error, context });
|
||||
}
|
||||
|
||||
error$(): Observable<{ error: Error; context?: ErrorContext }> {
|
||||
error$(): Observable<{ error: Error; context?: ErrorApiErrorContext }> {
|
||||
return this.subject;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { ErrorApi, ErrorContext } from '@backstage/core-plugin-api';
|
||||
import {
|
||||
ErrorApi,
|
||||
ErrorApiError,
|
||||
ErrorApiErrorContext,
|
||||
} from '@backstage/core-plugin-api';
|
||||
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
@@ -25,11 +29,11 @@ export class UnhandledErrorForwarder {
|
||||
/**
|
||||
* Add event listener, such that unhandled errors can be forwarded using an given `ErrorApi` instance
|
||||
*/
|
||||
static forward(errorApi: ErrorApi, errorContext: ErrorContext) {
|
||||
static forward(errorApi: ErrorApi, errorContext: ErrorApiErrorContext) {
|
||||
window.addEventListener(
|
||||
'unhandledrejection',
|
||||
(e: PromiseRejectionEvent) => {
|
||||
errorApi.post(e.reason as Error, errorContext);
|
||||
errorApi.post(e.reason as ErrorApiError, errorContext);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ import { AnalyticsApi } from '@backstage/core-plugin-api';
|
||||
import { AnalyticsEvent } from '@backstage/core-plugin-api';
|
||||
import { ComponentType } from 'react';
|
||||
import { ErrorApi } from '@backstage/core-plugin-api';
|
||||
import { ErrorContext } from '@backstage/core-plugin-api';
|
||||
import { ErrorApiError } from '@backstage/core-plugin-api';
|
||||
import { ErrorApiErrorContext } from '@backstage/core-plugin-api';
|
||||
import { ExternalRouteRef } from '@backstage/core-plugin-api';
|
||||
import { Observable } from '@backstage/types';
|
||||
import { ReactElement } from 'react';
|
||||
@@ -27,8 +28,8 @@ export type CollectedLogs<T extends LogFuncs> = {
|
||||
|
||||
// @public
|
||||
export type ErrorWithContext = {
|
||||
error: Error;
|
||||
context?: ErrorContext;
|
||||
error: ErrorApiError;
|
||||
context?: ErrorApiErrorContext;
|
||||
};
|
||||
|
||||
// @public @deprecated (undocumented)
|
||||
@@ -109,13 +110,13 @@ export class MockErrorApi implements ErrorApi {
|
||||
constructor(options?: MockErrorApiOptions);
|
||||
// (undocumented)
|
||||
error$(): Observable<{
|
||||
error: Error;
|
||||
context?: ErrorContext;
|
||||
error: ErrorApiError;
|
||||
context?: ErrorApiErrorContext;
|
||||
}>;
|
||||
// (undocumented)
|
||||
getErrors(): ErrorWithContext[];
|
||||
// (undocumented)
|
||||
post(error: Error, context?: ErrorContext): void;
|
||||
post(error: ErrorApiError, context?: ErrorApiErrorContext): void;
|
||||
// (undocumented)
|
||||
waitForError(pattern: RegExp, timeoutMs?: number): Promise<ErrorWithContext>;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ErrorApi, ErrorContext } from '@backstage/core-plugin-api';
|
||||
import {
|
||||
ErrorApi,
|
||||
ErrorApiError,
|
||||
ErrorApiErrorContext,
|
||||
} from '@backstage/core-plugin-api';
|
||||
import { Observable } from '@backstage/types';
|
||||
|
||||
/**
|
||||
@@ -27,12 +31,12 @@ export type MockErrorApiOptions = {
|
||||
};
|
||||
|
||||
/**
|
||||
* ErrorWithContext contains error and ErrorContext
|
||||
* ErrorWithContext contains error and ErrorApiErrorContext
|
||||
* @public
|
||||
*/
|
||||
export type ErrorWithContext = {
|
||||
error: Error;
|
||||
context?: ErrorContext;
|
||||
error: ErrorApiError;
|
||||
context?: ErrorApiErrorContext;
|
||||
};
|
||||
|
||||
type Waiter = {
|
||||
@@ -59,7 +63,7 @@ export class MockErrorApi implements ErrorApi {
|
||||
|
||||
constructor(private readonly options: MockErrorApiOptions = {}) {}
|
||||
|
||||
post(error: Error, context?: ErrorContext) {
|
||||
post(error: ErrorApiError, context?: ErrorApiErrorContext) {
|
||||
if (this.options.collect) {
|
||||
this.errors.push({ error, context });
|
||||
|
||||
@@ -76,7 +80,10 @@ export class MockErrorApi implements ErrorApi {
|
||||
throw new Error(`MockErrorApi received unexpected error, ${error}`);
|
||||
}
|
||||
|
||||
error$(): Observable<{ error: Error; context?: ErrorContext }> {
|
||||
error$(): Observable<{
|
||||
error: ErrorApiError;
|
||||
context?: ErrorApiErrorContext;
|
||||
}> {
|
||||
return nullObservable;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user