I dont know much about python, but when building graphql api, after long trial and error we went with structure like this:
{
"errors": {},
"results": {}
}
Errors is empty when there are no errors, and populated when something went wrong. We found out that it is easier to handle both cases when return values are consistent.
Hi, and thanks for the reply :)
Yeah, I was thinking of using a dictionary in a similar fashion, where one key-value pair is used to indicate if there was any trouble or not.
Having a key error seems like a nice way to create the necessary feed back in a standardized way.
try:data=get_one({"name":"joe"})exceptConnectionError:# handle a ConnectionError
else:# if no exceptions were raised then the data is presumed to be good
do_something_with(data)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I dont know much about python, but when building graphql api, after long trial and error we went with structure like this:
Errors is empty when there are no errors, and populated when something went wrong. We found out that it is easier to handle both cases when return values are consistent.
Hi, and thanks for the reply :)
Yeah, I was thinking of using a dictionary in a similar fashion, where one key-value pair is used to indicate if there was any trouble or not.
Having a key
error
seems like a nice way to create the necessary feed back in a standardized way.this is preferable