From 847124ad2c0ec871af1ac166832bf050be0d9442 Mon Sep 17 00:00:00 2001 From: MURAKAMI Masahiko Date: Sat, 14 Dec 2024 10:13:25 +0900 Subject: [PATCH] fix: throw AmplifyUserError instead of Error --- packages/backend-function/src/factory.test.ts | 21 +++++++++++-------- packages/backend-function/src/factory.ts | 7 ++++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/backend-function/src/factory.test.ts b/packages/backend-function/src/factory.test.ts index 5a5e79f2eb..7f7abffd1d 100644 --- a/packages/backend-function/src/factory.test.ts +++ b/packages/backend-function/src/factory.test.ts @@ -714,9 +714,10 @@ void describe('AmplifyFunctionFactory', () => { entry: './test-assets/default-lambda/handler.ts', ephemeralStorageSizeMB: 511, }).getInstance(getInstanceProps), - new Error( - 'ephemeralStorageSizeMB must be a whole number between 512 and 10240 inclusive' - ) + new AmplifyUserError('InvalidEphemeralStorageSizeMBError', { + message: `Invalid function ephemeralStorageSizeMB of 511`, + resolution: `ephemeralStorageSizeMB must be a whole number between 512 and 10240 inclusive`, + }) ); }); @@ -727,9 +728,10 @@ void describe('AmplifyFunctionFactory', () => { entry: './test-assets/default-lambda/handler.ts', ephemeralStorageSizeMB: 10241, }).getInstance(getInstanceProps), - new Error( - 'ephemeralStorageSizeMB must be a whole number between 512 and 10240 inclusive' - ) + new AmplifyUserError('InvalidEphemeralStorageSizeMBError', { + message: `Invalid function ephemeralStorageSizeMB of 10241`, + resolution: `ephemeralStorageSizeMB must be a whole number between 512 and 10240 inclusive`, + }) ); }); @@ -740,9 +742,10 @@ void describe('AmplifyFunctionFactory', () => { entry: './test-assets/default-lambda/handler.ts', ephemeralStorageSizeMB: 512.5, }).getInstance(getInstanceProps), - new Error( - 'ephemeralStorageSizeMB must be a whole number between 512 and 10240 inclusive' - ) + new AmplifyUserError('InvalidEphemeralStorageSizeMBError', { + message: `Invalid function ephemeralStorageSizeMB of 512.5`, + resolution: `ephemeralStorageSizeMB must be a whole number between 512 and 10240 inclusive`, + }) ); }); }); diff --git a/packages/backend-function/src/factory.ts b/packages/backend-function/src/factory.ts index 91b7d52c3d..7f2f04b081 100644 --- a/packages/backend-function/src/factory.ts +++ b/packages/backend-function/src/factory.ts @@ -346,9 +346,10 @@ class FunctionFactory implements ConstructFactory { ephemeralStorageSizeMax ) ) { - throw new Error( - `ephemeralStorageSizeMB must be a whole number between ${ephemeralStorageSizeMin} and ${ephemeralStorageSizeMax} inclusive` - ); + throw new AmplifyUserError('InvalidEphemeralStorageSizeMBError', { + message: `Invalid function ephemeralStorageSizeMB of ${this.props.ephemeralStorageSizeMB}`, + resolution: `ephemeralStorageSizeMB must be a whole number between ${ephemeralStorageSizeMin} and ${ephemeralStorageSizeMax} inclusive`, + }); } return this.props.ephemeralStorageSizeMB; };