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

Fixed issue where we failed to store response from 1 or more endpoints #2513

Merged
merged 1 commit into from
Jun 25, 2018
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
Fixed issue where we failed to store response from 1 or more endpoints
- Ensure that we process the repsonse from all endpoints that haven't failed
- Caused by minor bug mixed with not checking if the error object had a false error property
- Renamed `errors` to `errorsCheck` to avoid future confusion
  • Loading branch information
richard-cox committed Jun 25, 2018
commit d3cc84fb56a9bb132f97ec7f53d32406db870b7c
24 changes: 12 additions & 12 deletions src/frontend/app/store/effects/api.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ export class APIEffect {
return this.handleMultiEndpoints(response, actionClone);
}),
mergeMap(response => {
const { entities, totalResults, totalPages, errors = [] } = response;
if (requestType === 'fetch' && (errors && errors.length > 0)) {
this.handleApiEvents(errors);
const { entities, totalResults, totalPages, errorsCheck = [] } = response;
if (requestType === 'fetch' && (errorsCheck && errorsCheck.length > 0)) {
this.handleApiEvents(errorsCheck);
}

let fakedAction, errorMessage;
errors.forEach(error => {
errorsCheck.forEach(error => {
if (error.error) {
// Dispatch a error action for the specific endpoint that's failed
fakedAction = { ...actionClone, endpointGuid: error.guid };
Expand All @@ -137,10 +137,10 @@ export class APIEffect {

// If this request only went out to a single endpoint ... and it failed... send the failed action now and avoid response validation.
// This allows requests sent to multiple endpoints to proceed even if one of those endpoints failed.
if (errors.length === 1 && errors[0].error) {
if (errorsCheck.length === 1 && errorsCheck[0].error) {
this.store.dispatch(new WrapperRequestActionFailed(
errorMessage,
{ ...actionClone, endpointGuid: errors[0].guid },
{ ...actionClone, endpointGuid: errorsCheck[0].guid },
requestType
));
return [];
Expand Down Expand Up @@ -268,15 +268,15 @@ export class APIEffect {
});
}

getEntities(apiAction: IRequestAction, data, errors: APIErrorCheck[]): {
getEntities(apiAction: IRequestAction, data, errorCheck: APIErrorCheck[]): {
entities: NormalizedResponse
totalResults: number,
totalPages: number,
} {
let totalResults = 0;
let totalPages = 0;
const allEntities = Object.keys(data)
.filter(guid => data[guid] !== null && !errors.findIndex(error => error.guid === guid))
.filter(guid => data[guid] !== null && errorCheck.findIndex(error => error.guid === guid && !error.error) >= 0)
.map(cfGuid => {
const cfData = data[cfGuid];
switch (apiAction.entityLocation) {
Expand Down Expand Up @@ -374,15 +374,15 @@ export class APIEffect {
entities,
totalResults,
totalPages,
errors: APIErrorCheck[]
errorsCheck: APIErrorCheck[]
} {
const errors = this.checkForErrors(resData, apiAction);
const errorsCheck = this.checkForErrors(resData, apiAction);
let entities;
let totalResults = 0;
let totalPages = 0;

if (resData) {
const entityData = this.getEntities(apiAction, resData, errors);
const entityData = this.getEntities(apiAction, resData, errorsCheck);
entities = entityData.entities;
totalResults = entityData.totalResults;
totalPages = entityData.totalPages;
Expand All @@ -398,7 +398,7 @@ export class APIEffect {
entities,
totalResults,
totalPages,
errors
errorsCheck
};
}

Expand Down