Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle electrodb errores gracefully inside a lambda function. #202

Open
Easy-Cloud-in opened this issue Dec 24, 2022 · 1 comment

Comments

@Easy-Cloud-in
Copy link

Hi, i have lambda function like this

export async function deleteSubcription(event: any) {
  const sub = paramValidation.safeParse(event.body.params);
  if (!sub.success) {
    throw createError(422, "Invalid input parameters!");
  } 
  try {
    let response = await SubscriptionEntity.delete({
      subId: sub.data.subId,
      planId: sub.data.planId,
    })
      .where((attr, op) => `${op.lte(attr.ref_count, 0)}`)
      .go();
    return {
      statusCode: "200",
      body: JSON.stringify({
        message: response,
        error: "",
      }),
    };
  } catch (error: any) {
    return {
      statusCode: error.statusCode,
      body: JSON.stringify({
        message: "",
        error: error,
      }),
    };
  }
}
export const handler = commonMiddy(deleteSubcription);

Electrodb throws an error but i am unable to catch it in my function code?
Any think i have to configure to catch errors ?

@sam3d
Copy link
Sponsor

sam3d commented Aug 30, 2023

It seems like the issue here is probably that the error you're catching is an ElectroDB error, but you're checking for statusCode (and in general relying on the error being a different type than what it actually is). What behaviour are you trying to achieve?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants