#Getting invalid url.

1 messages · Page 1 of 1 (latest)

half bolt
#

My code:

export async function getUserConnections(id: string): Promise<Connection[]> {
    const connections: Connection[] = await fetch(`/api/user/${id}/connections`).then((res) =>
        res.json()
    );

    console.log("connections", connections);
    return connections || [];
}
hallow archBOT
#

Hi @half bolt. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the knowledge sources provided, it seems like you're encountering an ERR_INVALID_URL error. This error typically occurs when the URL you're trying to fetch is not valid or not properly formatted.

In your case, you're trying to fetch data from /api/user/${id}/connections. This is a relative URL, and it might be causing issues if it's used in a context where the base URL is not properly defined or not what you expect it to be.

Here are a few things you can try:

  1. Make sure the id variable in your URL is defined and properly formatted. An undefined or improperly formatted id could result in an invalid URL.

  2. If you're running this code on the server-side (for example, in a Next.js API route or in getServerSideProps), you might need to use an absolute URL instead of a relative one. This is because server-side code doesn't have the same concept of a "current page" as client-side code does.

  3. If you're running this code on the client-side, make sure your application is properly configured to handle the /api/user/[id]/connections route.

  4. Check your Next.js and Node.js versions. The knowledge sources mention issues with certain versions of Next.js and Node.js causing ERR_INVALID_URL errors.

If none of these suggestions help, you might want to look into the Next.js error handling documentation (https://nextjs.org/docs/app/building-your-application/routing/error-handling#next-steps) or the Vercel troubleshooting guide (https://vercel.com/docs/projects/domains/working-with-domains#troubleshooting) for more information.

Please note that without more context or information about your specific setup, it's hard to provide a more specific solution.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: