Programming languages enthusiast. Author of Learn Type Driven Development: https://www.packtpub.com/application-development/learn-type-driven-development
This will resolve with a Js.Promise.t(Belt.Result.t(response, error)) meaning the service didn't return an error message but the JSON may or may not have parsed successfully, or reject with your exception containing the service error message.
Check out github.com/ryb73/ppx_decco , it's a JSON codec PPX. It should work something like this:
Now it can decode a
Js.Json.t
that you got fromFetch.Response.json
:This will resolve with a
Js.Promise.t(Belt.Result.t(response, error))
meaning the service didn't return an error message but the JSON may or may not have parsed successfully, or reject with your exception containing the service error message.This syntax looks much cleaner ๐คฉ. I will give it a try soon with the Request module and comment about it in this part of the article. Thank you!