appwrite / sdk-for-node

[READ-ONLY] Official Appwrite Node.js SDK 🟒

Home Page:https://appwrite.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ› Bug Report: AppwriteException response is mis classified as a string

codercatdev opened this issue Β· comments

πŸ‘Ÿ Reproduction steps

Call method that returns an error. It will show the response as an object, but TS is typed as a string.

This will show

AppwriteException [Error]: A user with the same email already exists in your project.
    at Client.call (/Users/ajonp/web/dubstep-stack/node_modules/node-appwrite/lib/client.js:171:31)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at Users.create (/Users/ajonp/web/dubstep-stack/node_modules/node-appwrite/lib/services/users.js:86:16)
    at createUser (/Users/ajonp/web/dubstep-stack/app/models/user.server.ts:10:16)
    at action5 (/Users/ajonp/web/dubstep-stack/app/routes/join.tsx:73:7)
    at Object.callRouteAction (/Users/ajonp/web/dubstep-stack/node_modules/@remix-run/server-runtime/dist/data.js:40:14)
    at handleDataRequest (/Users/ajonp/web/dubstep-stack/node_modules/@remix-run/server-runtime/dist/server.js:94:18)
    at requestHandler (/Users/ajonp/web/dubstep-stack/node_modules/@remix-run/server-runtime/dist/server.js:34:18)
    at /Users/ajonp/web/dubstep-stack/node_modules/@remix-run/express/dist/server.js:39:22 {
  code: 409,
  type: 'user_already_exists',
  response: {
    message: 'A user with the same email already exists in your project.',
    code: 409,
    type: 'user_already_exists',
    version: '1.0.1'
  }
}

πŸ‘ Expected behavior

export class AppwriteException extends Error {

TS should change from

  export class AppwriteException extends Error {
    public code: number | null;
    public response: string | null;
    constructor(message: string, code?: number, response?: string);
  }

to

export class AppwriteException extends Error {
  public code: number | null;
  public response: AppwriteExceptionResponse | null;
  constructor(message: string, code?: number, response?: string);
}
  export type AppwriteExceptionResponse = {
    message:  string,
    code: number,
    type: string,
    version: number
  }
}

πŸ‘Ž Actual Behavior

catch (error) {
    let message = 'Unknown Error'
    if (error instanceof AppwriteException) message = error?.response != null ? error.response : message;
    return json<ActionData>(
      { errors: { email: `${message} for ${email}` } },
      { status: 400 }
    );
  }

Causes [object Object]

🎲 Appwrite version

Version 0.10.x

πŸ’» Operating system

MacOS

🧱 Your Environment

No

πŸ‘€ Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏒 Have you read the Code of Conduct?

Resolved by #46