Skip to content

Commit

Permalink
[MI-3635] Updated code to display proper errors on UI:
Browse files Browse the repository at this point in the history
1. Updated the backend code to return proper errors instead of empty response for the "get-search-autocomplete-fields" and "get-search-users" API.
2. Updated UI code to display a generic error in case of "get-search-autocomplete-fields" and "get-search-users" API calls.
  • Loading branch information
raghavaggarwal2308 committed Oct 17, 2023
1 parent d1e233a commit 36936a5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
24 changes: 10 additions & 14 deletions server/autocomplete_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,27 @@ func (p *Plugin) httpGetAutoCompleteFields(w http.ResponseWriter, r *http.Reques

client, _, _, err := p.getClient(types.ID(instanceID), types.ID(mattermostUserID))
if err != nil {
return http.StatusInternalServerError, err
return respondErr(w, http.StatusInternalServerError, err)
}

results, err := client.SearchAutoCompleteFields(params)
if err != nil {
return http.StatusInternalServerError, err
return respondErr(w, http.StatusInternalServerError, err)
}

if results == nil {
return http.StatusInternalServerError, errors.New("failed to return any results")
return respondErr(w, http.StatusInternalServerError, errors.New("failed to return any results"))
}

bb, err := json.Marshal(results)
if err != nil {
return http.StatusInternalServerError,
errors.WithMessage(err, "failed to marshal response")
return respondErr(w, http.StatusInternalServerError, errors.WithMessage(err, "failed to marshal response"))
}

w.Header().Set("Content-Type", "application/json")
_, err = w.Write(bb)
if err != nil {
return http.StatusInternalServerError,
errors.WithMessage(err, "failed to write response")
return respondErr(w, http.StatusInternalServerError, errors.WithMessage(err, "failed to write response"))
}
return http.StatusOK, nil
}
Expand All @@ -57,30 +55,28 @@ func (p *Plugin) httpGetSearchUsers(w http.ResponseWriter, r *http.Request) (int

client, _, _, err := p.getClient(types.ID(instanceID), types.ID(mattermostUserID))
if err != nil {
return http.StatusInternalServerError, err
return respondErr(w, http.StatusInternalServerError, err)
}

// Get list of assignable users
jiraUsers, err := client.SearchUsersAssignableInProject(projectKey, userSearch, 10)
if StatusCode(err) == 401 {
return http.StatusInternalServerError, err
return respondErr(w, http.StatusInternalServerError, err)
}

if jiraUsers == nil {
return http.StatusInternalServerError, errors.New("failed to return any results")
return respondErr(w, http.StatusInternalServerError, errors.New("failed to return any results"))
}

bb, err := json.Marshal(jiraUsers)
if err != nil {
return http.StatusInternalServerError,
errors.WithMessage(err, "failed to marshal response")
return respondErr(w, http.StatusInternalServerError, errors.WithMessage(err, "failed to marshal response"))
}

w.Header().Set("Content-Type", "application/json")
_, err = w.Write(bb)
if err != nil {
return http.StatusInternalServerError,
errors.WithMessage(err, "failed to write response")
return http.StatusInternalServerError, errors.WithMessage(err, "failed to write response")
}
return http.StatusOK, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export default class JiraAutoCompleteSelector extends React.PureComponent<Props>
value: suggestion.value,
label: stripHTML(suggestion.displayName),
}));
}).catch((e) => {
throw new Error('Error fetching data');
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export default class JiraUserSelector extends React.PureComponent<Props> {
label,
};
});
}).catch((e) => {
throw new Error('Error fetching data');
});
};

Expand Down

0 comments on commit 36936a5

Please sign in to comment.