URL Shortener Microservice Invalid URL Test Case failing

Hi everyone,
I’m solving the URL Shortener Microsevice challenge and I can’t seem to to pass the invalid url challenge. I’m using the valid-url package to check if it is a valid uri. I’ll leave the relevant code and output below. Any hints will be appreciated. Thanks!

app.post("/api/shorturl/", async function(req, res) {
  let url = req.body.url;
  if (!url) {
    return res.json({
      error: "invalid url"
    })
  }
  let urlCode = shortId.generate();
  if (!(validURL.isUri(url))) {
    return res.json({
      error: "invalid url"
    })
  }
  else {
    try {
      let one;
      one = await URL.findOne({ original_url: url });
      if (one) {
        return res.json({
          'original_url': one.original_url,
          'short_url': one.short_url
        })
      }
      else {
        one = new URL({
          'original_url': url,
          'short_url': urlCode
        })
        await one.save();
        return res.json({
          'original_url': one.original_url,
          'short_url': one.short_url
        });
      }
    } catch (err) {
      return res.json({ error: 'invalid url' })
    }
  }
})

I provided an Invalid URL to debug the code and here is the output for this url : “stackoverflow.com
image

Hi everyone, I figured the issue. It was related to how i was checking a valid url. The test cases only treat http and https urls as valid. However the isUri() method will return true for ftp urls as well. I added a check to only for this before isUri method.

/

/ Check if the URL starts with "http://" or "https://"
  if (!url.startsWith('http://') && !url.startsWith('https://')) {
    console.log("invalid url");
    return res.json({
      error: "invalid url"
    });
  }