Back

Failed to construct Error in

  • 0
  • Auth
  • Web
  • Storage
namay3635
26 Apr, 2024, 16:02

i am facing this error while using the appwrite service to create a blog platform . i have cross checked all the env variables . this is the piece of code where i am setting up the client and account and using them in a try catch and then using it in the app.js i have done all the necessary imports . still unable to understand the error and dont know how to solve it export class AuthService { client = new Client(); account;

TypeScript
constructor() {
    this.client
        .setEndpoint(conf.appWriteUrl)
        .setProject(conf.appWriteProjectId);
    this.account = new Account(this.client);
        
}

async getCurrentUser() { try { return await this.account.get();

TypeScript
    } catch (error) {
        console.log("Appwrite service :: getCurrentUser :: error", error);
    }

    return null;
}

}

TL;DR
Developers are encountering a "Failed to construct Error" message, likely due to a malformed endpoint being passed into the client for an API. Make sure to avoid direct API access and adhere to coding practices (like using backticks for code formatting). There seems to be an issue with the `conf.appWriteUrl` variable. Check environment variables for correctness and the code setup for Appwrite service when creating a blog platform.
VincentGe
26 Apr, 2024, 16:09

Can you log the conf.appWriteUrl real quick?

Steven
26 Apr, 2024, 16:09

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting).

namay3635
26 Apr, 2024, 16:22

it gives undefined and when i click on the endpoint it also gives this. i am not sure if the endpoint url is supposed to give this or not .

namay3635
26 Apr, 2024, 16:24

thanks a lot for the insight i ll surely keep in this in mind

VincentGe
26 Apr, 2024, 16:38

this is expected, ur not meant to access the api directly

VincentGe
26 Apr, 2024, 16:38

Can i see the full variable primted?

VincentGe
26 Apr, 2024, 16:39

The error is probably malformed endpoint passed into client

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more