Skip to content

Instantly share code, notes, and snippets.

@webbower
webbower / 01-handle-application-response-codes.js
Last active September 24, 2021 21:23
Complex Promise handling examples
zhuLiDoTheThing(args)
// Application status codes can come from HTTP 2xx, 4xx, and 5xx responses. This `.then()` will attempt to resolve
// to Promise<codeString> or reject with an error if the code is missing from the response body.
.then(
response => {
if (response.code) {
// Forward the code from the response
return response.code;
}