ipfs / pinning-services-api-spec

Standalone, vendor-agnostic Pinning Service API for IPFS ecosystem
https://ipfs.github.io/pinning-services-api-spec/
Creative Commons Zero v1.0 Universal
100 stars 27 forks source link

feat: improved error responses #59

Closed lidel closed 3 years ago

lidel commented 3 years ago

This PR:

2020-09-02--12-54-07

PREVIEW: https://ipfs.github.io/pinning-services-api-spec/#specUrl=https://raw.githubusercontent.com/ipfs/pinning-services-api-spec/feat/error-codes/ipfs-pinning-service.yaml

Closes #57 @obo20 @andrew @GregTheGreek @priom @jsign @sanderpick @andrewxhill @ipfs/wg-pinning-services

Please provide feedback (even if its just :+1: / :-1:)

obo20 commented 3 years ago

This looks good to me!

andrew commented 3 years ago

Only thing that springs to mind here is that sometimes the http infrastructure hosting the pinning service API may kick out a different 4XX or 5XX error code before the application server running the API gets chance to respond, clients should probably make sure they handle a variety of regular http errors along side the errors returned from IPFS itself.

jacobheun commented 3 years ago

I think the change to the error response is good, but I don't think we should be getting rid of the other http status codes. At the very least we should retain the 500 response. Having each of the 400 codes we've already added helps to clarify the category of error that should be expected when implementing/using this api.

obo20 commented 3 years ago

@lidel I agree with @jacobheun on this one. I think it would be beneficial to maintain the original 400-500 error codes that we had before.

The only changes I think that are needed is just the actual error object that's returned

priom commented 3 years ago

This is a good base to continue, but also an application will handle a variety of 200, 400 & 500 for specific errors ans responses so client can be very informative about it.

lidel commented 3 years ago

Thank you for feedback!

Q: is generic 400 enough as "catch-all" type of error? Or should we add separate 4XX for "custom errors" not covered by the spec?

jacobheun commented 3 years ago

Q: is generic 400 enough as "catch-all" type of error? Or should we add separate 4XX for "custom errors" not covered by the spec?

I think adding the additional 4XX for other errors would be useful. To me this implies that while we've documented common errors you might see, the API may still return other errors, such as 405 which we haven't covered. Should these also be required to return the same error object format as the other, defined 4xx codes? I'm leaning yes, but am somewhat concerned about adding an early restriction on this for code ranges.

lidel commented 3 years ago

Added 4XX:

Screenshot_2020-09-07 IPFS Pinning Service API

2020-09-07--15-10-37

As for suggesting specific response format for 4XX, those should be ok, as this type of error will be returned by the pinning service app.

The problematic one may be 5XX, where response can come from a reverse proxy that timeouts while trying to talk to the service app. One can configure proxy to return errors in specific format, but realistically one can't assume 5XX error body will known, so clients usually check only the status code, body would be optional/best-effort.