title: TypeError: Cannot read properties of undefined (reading 'location') in res.redirect
body: <p>I have the following function to retrieve an object from a database and extract an URL:</p>
  <pre><code>async redirect(id: string, redirectFunction: Function) {
      if (!IdExists(id)) {
        throw new Error(`ID ${id} does not exist.`);
      }
      const redirectLocation: string = await prisma.url.findUnique({
          where: { uniqueId: id },
          select: { url: true },
      }).then((data) =&gt; {
          return data?.url!;
      });
  
      redirectFunction('http://' + redirectLocation); 
  }
  </code></pre>
  <p>The function is called in the following segment of code:</p>
  <pre><code>app.get('/:id', async (req, res) =&gt; {
      try {
        redirectController.redirect(req.params.id, res.redirect);
      } catch (error) {
        console.error(error);
      } 
  });
  </code></pre>
  <p>However, I get the <code>TypeError: Cannot read properties of undefined (reading 'location')</code>, I see that the error is related to the <code>res.redirect</code> method. However, when I replace it by <code>console.log</code> for debugging, the URL is showed properly. What may be causing this error?</p>