Or, let me rephrase the question If only a User Object is returned from this. how do I pick response status code?
you can't. The SDK will only return the body
Failed API calls will throw an exception. The AppwriteException has a code which is the status code
Is there also a range of 200 codes?
Status code on success would be a nice addition for 2xx checks
Is there any good reason why status code prop is left out from success? Isn't it usually a common practice to have them?
the SDK abstracts that away to make things easier. if the API call is successful, you get the data back. If it's not successful, an exception is thrown
But limits us a little bit from making custom responses based on status codes as we can't pick them all right now
what is that? why exactly do you need the status code? what are you trying to do?
For example, if some API would return 200, I can make custom message for that one and return it to the client side to display it to the user. Same with 201 and other 2xx code.
what custom message? do you have a more concrete example or detail?
Whatever you'd like to say. For example, if https status code is 201, then I can return a message like "Your account is created"...if 202 - "We are processing your request"... While you probably have a range of what http status codes you return on failure, it would be nice to have it on success as well
do you have actual code sample? because i'm not really understanding the need
you make an api call:
try {
final document = databases.createDocument();
print("your document is created");
} catch (e) {
print("failed to create your document");
}
i don't need the HTTP status code
const response = {
message: '',
statusCode: 400
}
try {
const r = await axios.get(url);
if (r.statusCode === 200) {
response.message = 'Your request was successfull';
response.statusCode = r.statusCode;
} else if (r.statuscode === 201) {
response.message = 'Your request was created';
response.statusCode = r.statusCode;
} . . . . . .
} catch (e) {
. . .
}
return response;
But I'd make switch function for it
And with this I can apply custom messages per cloud function, or make more general ones...
per cloud function? Are you referring to Appwrite Functions?
Yes
But doesn't need to apply just to functions, can apply elsewhere as well
sorry i still don't see the value in what you're trying to do...
π€·
Often clients (and servers too) are using status codes to do stuff based on what the code is.
Especially with Restful APIs
Ya I understand what status codes are and what they mean. But I don't understand their practical importance in how you're using the SDK in your app
Well, my current use case (for now) is to set and return custom messages to the client side. Another use case might be setting specific component or global states on the client side based on the certain HTTP status code - to which I didn't get yet code-wise, in the current project.
You can already show custom messages
try {
final document = databases.createDocument();
print("your document is created");
} catch (e) {
print("failed to create your document");
}
If you're calling create document, and it's successful, a document was created
Recommended threads
- Download appwrite Docs
Is there is a way to download appwrite Docs ? Because appwrite skill isn't enough to give the agent full understanding about how appwrite works (I noticed this ...
- How do you contact support to cancel a s...
My nephew signed up with my CC without my permission and has forgotten the password to the account. I can't for the life of me get a hold of anyone at appwrite....
- I have try to use the appwrite in to the...
Invalid Origin. Register your new client (oailedjdbkhlkakmnnapoonllbnfmfij) as a new Web (Chrome Extension) platform on your project console dashboard