Skip to content

Commit

Permalink
Fix: http-envelope-normalizer: return request object (#13882)
Browse files Browse the repository at this point in the history
Resolves #13791

This wrapper appears to try and detect error-like messages in responses
from `wpcom.js` calls and turn them into proper JavaScript `Error`s.

Previously however instead of returning the request object it created it
was returning `undefined`. `wpcom.js` is supposed to return _either_ an
XHR object _or_ a promise for the request. In this case, any code
depending on the return value (XHR updloads, promise resolvers, etc...)
would throw a `TypeError` because `undefined` has no properties.

Now the code _returns_ the augmented request object instead of merely
_calling_ it.

cc: @retrofox
  • Loading branch information
dmsnell authored and astralbodies committed May 17, 2017
1 parent 8b1a960 commit ba3d1f0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions client/lib/wp/handlers/http-envelope-normalizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @return {Function} handler wrapper
*/
export function requestHandler( handler ) {
return ( params, fn ) => {
return ( params, fn ) => (
handler( params, ( err, response ) => {
const { code, message, data = {} } = response || {};
const { status } = data;
Expand All @@ -21,8 +21,8 @@ export function requestHandler( handler ) {
}

return fn( err, response );
} );
};
} )
);
}

/**
Expand Down

0 comments on commit ba3d1f0

Please sign in to comment.