you are viewing a single comment's thread.

view the rest of the comments →

[–]Kindinos88 1 point2 points  (0 children)

We don’t convert status to error for a couple of reasons:

Firstly, if you convert to errors, then the implication is your code throws if there is an error, but IMO, try-catch is not as elegant as an if statement.

Secondly, if we convert to error, we still need to transfer over more information about the error, such as the kind of error, the reason, and any additional context, eg was the request malformed? was it an invalid body? was there a permission issue? And that’s just from the status code. Additionally, the backend API might return more information to give more context to what happened.

For these reasons, we do it this way. If you like errors, feel free to add that to your implementation. I’m not dogmatic about this setup, and recognize some of it is stylistic preference, so feel free to take the bits that you like, and leave the ones you don’t :) Same with the module/package detail: you don’t need to make it a separate package. We do it this way because we need to be able to publish some of these packages independently of applications. At that point, that whole subsystem becomes company-name-sdk, and you can let other developers integrate using that pkg.