Skip to content

Commit

Permalink
fix: throw AmplifyUserError instead of Error
Browse files Browse the repository at this point in the history
  • Loading branch information
fossamagna committed Dec 14, 2024
1 parent 6c8d04f commit 847124a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
21 changes: 12 additions & 9 deletions packages/backend-function/src/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
})
);
});

Expand All @@ -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`,
})
);
});

Expand All @@ -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`,
})
);
});
});
Expand Down
7 changes: 4 additions & 3 deletions packages/backend-function/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,10 @@ class FunctionFactory implements ConstructFactory<AmplifyFunction> {
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;
};
Expand Down

0 comments on commit 847124a

Please sign in to comment.