Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix circular dependency in wpcom-xhr-wrapper #42785

Merged
merged 1 commit into from
May 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions client/lib/wpcom-xhr-wrapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import debugModule from 'debug';
*/
const debug = debugModule( 'calypso:wpcom-xhr-wrapper' );

export default function ( params, callback ) {
return import( /* webpackChunkName: "wpcom-xhr-request" */ 'wpcom-xhr-request' ).then( ( xhr ) =>
xhr.default( params, function ( error, response, headers ) {
if ( error && error.name === 'InvalidTokenError' ) {
debug( 'Invalid token error detected, authorisation probably revoked - logging out' );
require( 'lib/user/utils' ).logout();
}
export default async function ( params, callback ) {
const xhr = ( await import( /* webpackChunkName: "wpcom-xhr-request" */ 'wpcom-xhr-request' ) )
.default;
const userUtils = ( await import( /* webpackChunkName: "lib-user-utils" */ 'lib/user/utils' ) )
.default;

callback( error, response, headers );
} )
);
return xhr( params, function ( error, response, headers ) {
if ( error && error.name === 'InvalidTokenError' ) {
debug( 'Invalid token error detected, authorisation probably revoked - logging out' );
userUtils.logout();
}

callback( error, response, headers );
} );
}