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

Early failure message when backend is down. #156

Closed
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/auth/AxiosJwtAuthService.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const optionsPropTypes = {
REFRESH_ACCESS_TOKEN_ENDPOINT: PropTypes.string.isRequired,
ACCESS_TOKEN_COOKIE_NAME: PropTypes.string.isRequired,
CSRF_TOKEN_API_PATH: PropTypes.string.isRequired,
SHOULD_RETRY: PropTypes.bool.isRequired,
}).isRequired,
loggingService: PropTypes.shape({
logError: PropTypes.func.isRequired,
Expand Down Expand Up @@ -58,6 +59,7 @@ class AxiosJwtAuthService {
this.loggingService,
this.config.ACCESS_TOKEN_COOKIE_NAME,
this.config.REFRESH_ACCESS_TOKEN_ENDPOINT,
this.config.SHOULD_RETRY,
);
this.csrfTokenService = new AxiosCsrfTokenService(this.config.CSRF_TOKEN_API_PATH);
this.authenticatedHttpClient = this.addAuthenticationToHttpClient(axios.create());
Expand Down
13 changes: 10 additions & 3 deletions src/auth/AxiosJwtTokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class AxiosJwtTokenService {
return !token || token.exp < Date.now() / 1000;
}

constructor(loggingService, tokenCookieName, tokenRefreshEndpoint) {
constructor(loggingService, tokenCookieName, tokenRefreshEndpoint, shouldRetry) {
this.loggingService = loggingService;
this.tokenCookieName = tokenCookieName;
this.tokenRefreshEndpoint = tokenRefreshEndpoint;
Expand All @@ -20,10 +20,17 @@ export default class AxiosJwtTokenService {
// certificates. More on MDN:
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials
this.httpClient.defaults.withCredentials = true;
// Add retries to this axios instance
const options = { httpClient: this.httpClient };
// Giving MFE option to fail early and show error message instead of
// recurrent retries.
if (!shouldRetry) {
console.log('shouldRetry');
options.shouldRetry = () => { return false; };
}

this.httpClient.interceptors.response.use(
response => response,
createRetryInterceptor({ httpClient: this.httpClient }),
createRetryInterceptor(options),
);

this.cookies = new Cookies();
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ let config = {
LOGO_TRADEMARK_URL: process.env.LOGO_TRADEMARK_URL,
LOGO_WHITE_URL: process.env.LOGO_WHITE_URL,
FAVICON_URL: process.env.FAVICON_URL,
SHOULD_RETRY: process.env.SHOULD_RETRY,
};

/**
Expand Down