diff --git a/packages/analytics/__tests__/errors/AnalyticsError.test.ts b/packages/analytics/__tests__/errors/AnalyticsError.test.ts new file mode 100644 index 00000000000..4fe6c626e07 --- /dev/null +++ b/packages/analytics/__tests__/errors/AnalyticsError.test.ts @@ -0,0 +1,12 @@ +import { AnalyticsError } from '../../src/errors/AnalyticsError'; + +describe('AnalyticsError', () => { + it('works with instanceof operator', () => { + const error = new AnalyticsError({ + name: 'TestError', + message: 'message', + }); + + expect(error instanceof AnalyticsError).toBe(true); + }); +}); diff --git a/packages/analytics/src/errors/AnalyticsError.ts b/packages/analytics/src/errors/AnalyticsError.ts index a3c1c29ac6a..c70cc5b77e8 100644 --- a/packages/analytics/src/errors/AnalyticsError.ts +++ b/packages/analytics/src/errors/AnalyticsError.ts @@ -1,21 +1,9 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { - AmplifyError, - AmplifyErrorParams, -} from '@aws-amplify/core/internals/utils'; +import { AmplifyError } from '@aws-amplify/core/internals/utils'; /** * @internal */ -export class AnalyticsError extends AmplifyError { - constructor(params: AmplifyErrorParams) { - super(params); - - // Hack for making the custom error class work when transpiled to es5 - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = AnalyticsError; - Object.setPrototypeOf(this, AnalyticsError.prototype); - } -} +export class AnalyticsError extends AmplifyError {} diff --git a/packages/api-graphql/__tests__/utils/errors/GraphQLApiError.test.ts b/packages/api-graphql/__tests__/utils/errors/GraphQLApiError.test.ts new file mode 100644 index 00000000000..87b1f14d17f --- /dev/null +++ b/packages/api-graphql/__tests__/utils/errors/GraphQLApiError.test.ts @@ -0,0 +1,12 @@ +import { GraphQLApiError } from '../../../src/utils/errors'; + +describe('GraphQLApiError', () => { + it('works with instanceof operator', () => { + const error = new GraphQLApiError({ + name: 'TestError', + message: 'message', + }); + + expect(error instanceof GraphQLApiError).toBe(true); + }); +}); diff --git a/packages/api-graphql/src/utils/errors/GraphQLApiError.ts b/packages/api-graphql/src/utils/errors/GraphQLApiError.ts index 77a80c08a90..22b4f14271b 100644 --- a/packages/api-graphql/src/utils/errors/GraphQLApiError.ts +++ b/packages/api-graphql/src/utils/errors/GraphQLApiError.ts @@ -1,21 +1,9 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { - AmplifyError, - AmplifyErrorParams, -} from '@aws-amplify/core/internals/utils'; +import { AmplifyError } from '@aws-amplify/core/internals/utils'; /** * @internal */ -export class GraphQLApiError extends AmplifyError { - constructor(params: AmplifyErrorParams) { - super(params); - - // Hack for making the custom error class work when transpiled to es5 - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = GraphQLApiError; - Object.setPrototypeOf(this, GraphQLApiError.prototype); - } -} +export class GraphQLApiError extends AmplifyError {} diff --git a/packages/api-rest/__tests__/errors/CanceledError.test.ts b/packages/api-rest/__tests__/errors/CanceledError.test.ts new file mode 100644 index 00000000000..de4329c5324 --- /dev/null +++ b/packages/api-rest/__tests__/errors/CanceledError.test.ts @@ -0,0 +1,12 @@ +import { CanceledError } from '../../src/errors'; + +describe('CanceledError', () => { + it('works with instanceof operator', () => { + const error = new CanceledError({ + name: 'TestError', + message: 'message', + }); + + expect(error instanceof CanceledError).toBe(true); + }); +}); diff --git a/packages/api-rest/__tests__/errors/RestApiError.test.ts b/packages/api-rest/__tests__/errors/RestApiError.test.ts new file mode 100644 index 00000000000..f5a53a5d4e3 --- /dev/null +++ b/packages/api-rest/__tests__/errors/RestApiError.test.ts @@ -0,0 +1,12 @@ +import { RestApiError } from '../../src/errors'; + +describe('RestApiError', () => { + it('works with instanceof operator', () => { + const error = new RestApiError({ + name: 'TestError', + message: 'message', + }); + + expect(error instanceof RestApiError).toBe(true); + }); +}); diff --git a/packages/api-rest/src/errors/CanceledError.ts b/packages/api-rest/src/errors/CanceledError.ts index ce4082212e0..56b7b99b6be 100644 --- a/packages/api-rest/src/errors/CanceledError.ts +++ b/packages/api-rest/src/errors/CanceledError.ts @@ -17,10 +17,6 @@ export class CanceledError extends RestApiError { message: 'Request is canceled by user', ...params, }); - - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = CanceledError; - Object.setPrototypeOf(this, CanceledError.prototype); } } diff --git a/packages/api-rest/src/errors/RestApiError.ts b/packages/api-rest/src/errors/RestApiError.ts index 1d2786010ba..30468c6f432 100644 --- a/packages/api-rest/src/errors/RestApiError.ts +++ b/packages/api-rest/src/errors/RestApiError.ts @@ -1,14 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { ApiError, ApiErrorParams } from '@aws-amplify/core/internals/utils'; +import { ApiError } from '@aws-amplify/core/internals/utils'; -export class RestApiError extends ApiError { - constructor(params: ApiErrorParams) { - super(params); - - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = RestApiError; - Object.setPrototypeOf(this, RestApiError.prototype); - } -} +export class RestApiError extends ApiError {} diff --git a/packages/auth/__tests__/Error.test.ts b/packages/auth/__tests__/Error.test.ts new file mode 100644 index 00000000000..9710e06da18 --- /dev/null +++ b/packages/auth/__tests__/Error.test.ts @@ -0,0 +1,10 @@ +import { NoUserPoolError } from '../src/Errors'; +import { AuthErrorTypes } from '../src/types/Auth'; + +describe('NoUserPoolError', () => { + it('works with instanceof operator', () => { + const error = new NoUserPoolError(AuthErrorTypes.NoConfig); + + expect(error instanceof NoUserPoolError).toBe(true); + }); +}); diff --git a/packages/auth/__tests__/errors/AuthError.test.ts b/packages/auth/__tests__/errors/AuthError.test.ts new file mode 100644 index 00000000000..4e69e2cd95c --- /dev/null +++ b/packages/auth/__tests__/errors/AuthError.test.ts @@ -0,0 +1,12 @@ +import { AuthError } from '../../src/errors/AuthError'; + +describe('AuthError', () => { + it('works with instanceof operator', () => { + const error = new AuthError({ + name: 'TestError', + message: 'message', + }); + + expect(error instanceof AuthError).toBe(true); + }); +}); diff --git a/packages/auth/src/Errors.ts b/packages/auth/src/Errors.ts index a64da33a0fb..216828724ff 100644 --- a/packages/auth/src/Errors.ts +++ b/packages/auth/src/Errors.ts @@ -16,11 +16,6 @@ export class AuthError extends Error { const { message, log } = authErrorMessages[type]; super(message); - // Hack for making the custom error class work when transpiled to es5 - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = AuthError; - Object.setPrototypeOf(this, AuthError.prototype); - this.name = 'AuthError'; this.log = log || message; @@ -32,11 +27,6 @@ export class NoUserPoolError extends AuthError { constructor(type: AuthErrorTypes) { super(type); - // Hack for making the custom error class work when transpiled to es5 - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = NoUserPoolError; - Object.setPrototypeOf(this, NoUserPoolError.prototype); - this.name = 'NoUserPoolError'; } } diff --git a/packages/auth/src/errors/AuthError.ts b/packages/auth/src/errors/AuthError.ts index ef3e6006e25..36791ab6068 100644 --- a/packages/auth/src/errors/AuthError.ts +++ b/packages/auth/src/errors/AuthError.ts @@ -1,18 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { - AmplifyError, - AmplifyErrorParams, -} from '@aws-amplify/core/internals/utils'; +import { AmplifyError } from '@aws-amplify/core/internals/utils'; -export class AuthError extends AmplifyError { - constructor(params: AmplifyErrorParams) { - super(params); - - // Hack for making the custom error class work when transpiled to es5 - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = AuthError; - Object.setPrototypeOf(this, AuthError.prototype); - } -} +export class AuthError extends AmplifyError {} diff --git a/packages/core/__tests__/errors/APIError.test.ts b/packages/core/__tests__/errors/APIError.test.ts new file mode 100644 index 00000000000..9e18eaab353 --- /dev/null +++ b/packages/core/__tests__/errors/APIError.test.ts @@ -0,0 +1,12 @@ +import { ApiError } from '../../src/errors/APIError'; + +describe('ApiError', () => { + it('works with instanceof operator', () => { + const error = new ApiError({ + name: 'TestError', + message: 'message', + }); + + expect(error instanceof ApiError).toBe(true); + }); +}); diff --git a/packages/core/__tests__/errors/AmplifyError.test.ts b/packages/core/__tests__/errors/AmplifyError.test.ts new file mode 100644 index 00000000000..f4200b5f670 --- /dev/null +++ b/packages/core/__tests__/errors/AmplifyError.test.ts @@ -0,0 +1,12 @@ +import { AmplifyError } from '../../src/errors/AmplifyError'; + +describe('AmplifyError', () => { + it('works with instanceof operator', () => { + const error = new AmplifyError({ + name: 'TestError', + message: 'message', + }); + + expect(error instanceof AmplifyError).toBe(true); + }); +}); diff --git a/packages/core/src/errors/APIError.ts b/packages/core/src/errors/APIError.ts index 16a8ae3bc44..a3654cbe02a 100644 --- a/packages/core/src/errors/APIError.ts +++ b/packages/core/src/errors/APIError.ts @@ -42,10 +42,6 @@ export class ApiError extends AmplifyError { constructor(params: ApiErrorParams) { super(params); - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = ApiError; - Object.setPrototypeOf(this, ApiError.prototype); - if (params.response) { this._response = params.response; } diff --git a/packages/core/src/errors/AmplifyError.ts b/packages/core/src/errors/AmplifyError.ts index 9d1c6759bf1..b402f9a5bab 100644 --- a/packages/core/src/errors/AmplifyError.ts +++ b/packages/core/src/errors/AmplifyError.ts @@ -25,10 +25,5 @@ export class AmplifyError extends Error { this.name = name; this.underlyingError = underlyingError; this.recoverySuggestion = recoverySuggestion; - - // Hack for making the custom error class work when transpiled to es5 - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = AmplifyError; - Object.setPrototypeOf(this, AmplifyError.prototype); } } diff --git a/packages/interactions/__tests__/errors/InteractionsError.test.ts b/packages/interactions/__tests__/errors/InteractionsError.test.ts new file mode 100644 index 00000000000..351dcfaac08 --- /dev/null +++ b/packages/interactions/__tests__/errors/InteractionsError.test.ts @@ -0,0 +1,12 @@ +import { InteractionsError } from '../../src/errors/InteractionsError'; + +describe('InteractionsError', () => { + it('works with instanceof operator', () => { + const error = new InteractionsError({ + name: 'TestError', + message: 'message', + }); + + expect(error instanceof InteractionsError).toBe(true); + }); +}); diff --git a/packages/interactions/src/errors/InteractionsError.ts b/packages/interactions/src/errors/InteractionsError.ts index 580809b3f48..5bf335acfca 100644 --- a/packages/interactions/src/errors/InteractionsError.ts +++ b/packages/interactions/src/errors/InteractionsError.ts @@ -1,18 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { - AmplifyError, - AmplifyErrorParams, -} from '@aws-amplify/core/internals/utils'; +import { AmplifyError } from '@aws-amplify/core/internals/utils'; -export class InteractionsError extends AmplifyError { - constructor(params: AmplifyErrorParams) { - super(params); - - // Hack for making the custom error class work when transpiled to es5 - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = InteractionsError; - Object.setPrototypeOf(this, InteractionsError.prototype); - } -} +export class InteractionsError extends AmplifyError {} diff --git a/packages/notifications/__tests__/inAppMessaging/errors/InAppMessagingError.test.ts b/packages/notifications/__tests__/inAppMessaging/errors/InAppMessagingError.test.ts new file mode 100644 index 00000000000..135215bbe3d --- /dev/null +++ b/packages/notifications/__tests__/inAppMessaging/errors/InAppMessagingError.test.ts @@ -0,0 +1,12 @@ +import { InAppMessagingError } from '../../../src/inAppMessaging/errors/InAppMessagingError'; + +describe('InAppMessagingError', () => { + it('works with instanceof operator', () => { + const error = new InAppMessagingError({ + name: 'TestError', + message: 'message', + }); + + expect(error instanceof InAppMessagingError).toBe(true); + }); +}); diff --git a/packages/notifications/__tests__/pushNotifications/errors/PushNotificationError.test.ts b/packages/notifications/__tests__/pushNotifications/errors/PushNotificationError.test.ts new file mode 100644 index 00000000000..f5aa94c770a --- /dev/null +++ b/packages/notifications/__tests__/pushNotifications/errors/PushNotificationError.test.ts @@ -0,0 +1,12 @@ +import { PushNotificationError } from '../../../src/pushNotifications/errors/PushNotificationError'; + +describe('PushNotificationError', () => { + it('works with instanceof operator', () => { + const error = new PushNotificationError({ + name: 'TestError', + message: 'message', + }); + + expect(error instanceof PushNotificationError).toBe(true); + }); +}); diff --git a/packages/notifications/src/inAppMessaging/errors/InAppMessagingError.ts b/packages/notifications/src/inAppMessaging/errors/InAppMessagingError.ts index ec4303a3684..b3e85c42258 100644 --- a/packages/notifications/src/inAppMessaging/errors/InAppMessagingError.ts +++ b/packages/notifications/src/inAppMessaging/errors/InAppMessagingError.ts @@ -1,21 +1,9 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { - AmplifyError, - AmplifyErrorParams, -} from '@aws-amplify/core/internals/utils'; +import { AmplifyError } from '@aws-amplify/core/internals/utils'; /** * @internal */ -export class InAppMessagingError extends AmplifyError { - constructor(params: AmplifyErrorParams) { - super(params); - - // Hack for making the custom error class work when transpiled to es5 - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = InAppMessagingError; - Object.setPrototypeOf(this, InAppMessagingError.prototype); - } -} +export class InAppMessagingError extends AmplifyError {} diff --git a/packages/notifications/src/pushNotifications/errors/PushNotificationError.ts b/packages/notifications/src/pushNotifications/errors/PushNotificationError.ts index ab2aa692a18..13a12f21006 100644 --- a/packages/notifications/src/pushNotifications/errors/PushNotificationError.ts +++ b/packages/notifications/src/pushNotifications/errors/PushNotificationError.ts @@ -1,18 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { - AmplifyError, - AmplifyErrorParams, -} from '@aws-amplify/core/internals/utils'; +import { AmplifyError } from '@aws-amplify/core/internals/utils'; -export class PushNotificationError extends AmplifyError { - constructor(params: AmplifyErrorParams) { - super(params); - - // Hack for making the custom error class work when transpiled to es5 - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = PushNotificationError; - Object.setPrototypeOf(this, PushNotificationError.prototype); - } -} +export class PushNotificationError extends AmplifyError {} diff --git a/packages/predictions/__tests__/errors/PredictionsError.test.ts b/packages/predictions/__tests__/errors/PredictionsError.test.ts new file mode 100644 index 00000000000..b0c85dd6185 --- /dev/null +++ b/packages/predictions/__tests__/errors/PredictionsError.test.ts @@ -0,0 +1,12 @@ +import { PredictionsError } from '../../src/errors/PredictionsError'; + +describe('PredictionsError', () => { + it('works with instanceof operator', () => { + const error = new PredictionsError({ + name: 'TestError', + message: 'message', + }); + + expect(error instanceof PredictionsError).toBe(true); + }); +}); diff --git a/packages/predictions/src/errors/PredictionsError.ts b/packages/predictions/src/errors/PredictionsError.ts index 21c97ca30b4..d596cca6576 100644 --- a/packages/predictions/src/errors/PredictionsError.ts +++ b/packages/predictions/src/errors/PredictionsError.ts @@ -1,16 +1,5 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { - AmplifyError, - AmplifyErrorParams, -} from '@aws-amplify/core/internals/utils'; +import { AmplifyError } from '@aws-amplify/core/internals/utils'; -export class PredictionsError extends AmplifyError { - constructor(params: AmplifyErrorParams) { - super(params); - - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = PredictionsError; - Object.setPrototypeOf(this, PredictionsError.prototype); - } -} +export class PredictionsError extends AmplifyError {} diff --git a/packages/storage/__tests__/errors/CanceledError.test.ts b/packages/storage/__tests__/errors/CanceledError.test.ts new file mode 100644 index 00000000000..ff63e913962 --- /dev/null +++ b/packages/storage/__tests__/errors/CanceledError.test.ts @@ -0,0 +1,12 @@ +import { CanceledError } from '../../src/errors/CanceledError'; + +describe('CanceledError', () => { + it('works with instanceof operator', () => { + const error = new CanceledError({ + name: 'TestError', + message: 'message', + }); + + expect(error instanceof CanceledError).toBe(true); + }); +}); diff --git a/packages/storage/__tests__/errors/StorageError.test.ts b/packages/storage/__tests__/errors/StorageError.test.ts new file mode 100644 index 00000000000..600e26c6137 --- /dev/null +++ b/packages/storage/__tests__/errors/StorageError.test.ts @@ -0,0 +1,12 @@ +import { StorageError } from '../../src/errors/StorageError'; + +describe('StorageError', () => { + it('works with instanceof operator', () => { + const error = new StorageError({ + name: 'TestError', + message: 'message', + }); + + expect(error instanceof StorageError).toBe(true); + }); +}); diff --git a/packages/storage/src/errors/CanceledError.ts b/packages/storage/src/errors/CanceledError.ts index 9388653432a..7011e7640a0 100644 --- a/packages/storage/src/errors/CanceledError.ts +++ b/packages/storage/src/errors/CanceledError.ts @@ -18,10 +18,6 @@ export class CanceledError extends StorageError { message: 'Upload is canceled by user', ...params, }); - - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = CanceledError; - Object.setPrototypeOf(this, CanceledError.prototype); } } diff --git a/packages/storage/src/errors/StorageError.ts b/packages/storage/src/errors/StorageError.ts index 0903c8eb835..9d707aee4ec 100644 --- a/packages/storage/src/errors/StorageError.ts +++ b/packages/storage/src/errors/StorageError.ts @@ -1,16 +1,5 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { - AmplifyError, - AmplifyErrorParams, -} from '@aws-amplify/core/internals/utils'; +import { AmplifyError } from '@aws-amplify/core/internals/utils'; -export class StorageError extends AmplifyError { - constructor(params: AmplifyErrorParams) { - super(params); - - // TODO: Delete the following 2 lines after we change the build target to >= es2015 - this.constructor = StorageError; - Object.setPrototypeOf(this, StorageError.prototype); - } -} +export class StorageError extends AmplifyError {}