Ficodes/ngsijs

status code is not provided when InvalidResponseError is obtained

AlvaroVega opened this issue · 3 comments

Cloned from conwetlab#54

status code is not provided when InvalidResponseError is obtained

https://github.com/conwetlab/ngsijs/blob/59ce53e2cfd7b486aa9580cbbc74dc339b134af2/dist/NGSI.js#L1687-L1691

InvalidResponseError could happens for example when PEP responses 401

Not sure if is really a bug or maybe just something that could be improved.
Others errors like InvalidRequestError are providing status code:

https://github.com/conwetlab/ngsijs/blob/59ce53e2cfd7b486aa9580cbbc74dc339b134af2/dist/NGSI.js#L1624-L1629

Hi @AlvaroVega!

Thanks for reporting this.

I think adding the status code to the InvalidRequestError exception would be a great addition as usually this error is raised as the response status code is not one of the expected ones. In addition, we are going to provide also the body of the response. Both details should provide a good way to check what the problem is.

That said, I was thinking about the 401 error code, and I think that error response should not be managed with the InvalidRequestError. So we are working on adding an UnauthorizedError exception for those cases as well as an ForbiddenError exception for the 403 status code. What do you think?

Absolutely, 401 and UnauthorizedError and 403 with ForbiddenError .
Thanks!

@aarranz does PR #23 solves this issue? Has been included that PR in some (numbered) version of the library? Thanks!