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

Early return inside a try/catch causing timeout #322

Open
felipe-heredia opened this issue Dec 18, 2024 · 0 comments
Open

Early return inside a try/catch causing timeout #322

felipe-heredia opened this issue Dec 18, 2024 · 0 comments

Comments

@felipe-heredia
Copy link

After updating the programming model from ^3.0.0 to ^4.6.0 and the runtime from 3.* to 4.* some functions that has try/catch and early return stop and return timeout.

async function emailValidator(req: HttpRequest): Promise<HttpResponseInit> {
  // ...
  try {
     const email_and_domain = email.split('@')

    if (email_and_domain.length < 2 || !isValidEmail(email)) {
      throw {
        message: `O Email ${email} inválido`,
        status: 400,
        type: InvalidEmailType.INVALID,
      }
    }

    const email_name = email_and_domain[0]
    const email_domain = email_and_domain[1]

    const domainAllowedList = await DomainAllowedListModel.findOne({
      domain: email_domain,
    })

    if (domainAllowedList) {
      response.status = 200
      response.jsonBody = {
        isValid: true,
        message: `O email ${email} é válido. Está na Lista de Autorizações`,
        email,
      }
      return
    }

   // code continues...
  } catch (err) {
    const status = err?.status || 500
    const message = err?.message

    response.status = status
    response.jsonBody = { message, status, ...err }
  }

  return response
}

The throw works good, also when !domainAllowedList the functions works properly, but when get into the return inside the if, the function stops and gives timeout after a couple minutes.

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

1 participant