toloka-kit
toloka-kit copied to clipboard
404 from API is not eloquent enough
Toloka API returns just 404 in case of inability to find a valid entity. But if I am making a request that uses few entities (like I am trying to set skills for workers -- I am using both worker and skill entities), there is no easy way to distinguish whether 404 is due because skill does not exist, or worker.
Hello, Vladislav! Unfortunately, I failed to reproduce your error with set_user_skill method.
If I pass wrong skill_id, I get
ValidationApiError(
status_code=400,
request_id='ac775943dff967d8df8f3a22a65f2c5b',
code='VALIDATION_ERROR',
message='Validation failed',
payload={'skill_id': {'code': 'ENTITY_DOES_NOT_EXIST', 'message': 'Entity does not exist'}}
)
If I pass wrong user_id, I get
ValidationApiError(
status_code=400,
request_id='9b9fed94164f7365aa4978c695afd169',
code='VALIDATION_ERROR',
message='Validation failed',
payload={'user_id': {'code': 'ENTITY_DOES_NOT_EXIST', 'message': 'Entity does not exist'}}
)
For me both errors had status codes 400, not 404 and the actual reason could be deduced from the payload
attribute of the error.
Could you please provide a minimal example to reproduce the problem?
Oh, that's on me.
Yeah, I did got 400 too (did not notice specific status code and thought it would be 404, since the code says DOES_NOT_EXIST. As for the eloquence, I just did not notice that in a payload the first parts says which specific parameters are missing on a Toloka's backend.
TBH, the message is not really friendly from my point of view, but not sure that is an issue.
I will double-check the error format and
- if backend guarantees that payload may only contain one error, we can raise more specific errors
- if not, we can think about more user-friendly exception message
Exceptions are enhanced in #106