toloka-kit icon indicating copy to clipboard operation
toloka-kit copied to clipboard

404 from API is not eloquent enough

Open TanVD opened this issue 3 years ago • 3 comments

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.

TanVD avatar Sep 01 '21 18:09 TanVD

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?

Losik avatar Sep 02 '21 20:09 Losik

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.

TanVD avatar Sep 02 '21 20:09 TanVD

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

Losik avatar Sep 02 '21 20:09 Losik

Exceptions are enhanced in #106

Pocoder avatar Nov 02 '22 14:11 Pocoder