π Bug Report: AppwriteException response is mis classified as a string
codercatdev opened this issue Β· comments
Alex Patterson commented
π 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
Line 1781 in 6caaeb8
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?
- I have read the Code of Conduct
Alex Patterson commented
Resolved by #46