Skip to content

Commit

Permalink
Handle req log filter I/O when no project is set
Browse files Browse the repository at this point in the history
  • Loading branch information
dstotijn committed Dec 29, 2020
1 parent 8c2efdb commit ad3fa7d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion admin/src/components/reqlog/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function Search(): JSX.Element {
FILTER,
{
onCompleted: (data) => {
setSearchExpr(data.httpRequestLogFilter.searchExpression || "");
setSearchExpr(data.httpRequestLogFilter?.searchExpression || "");
},
}
);
Expand All @@ -108,6 +108,7 @@ function Search(): JSX.Element {
},
});
},
onError: () => {},
});

const [
Expand Down
24 changes: 16 additions & 8 deletions pkg/api/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ func (r *Resolver) Mutation() MutationResolver { return &mutationResolver{r} }
func (r *queryResolver) HTTPRequestLogs(ctx context.Context) ([]HTTPRequestLog, error) {
reqs, err := r.RequestLogService.FindRequests(ctx)
if err == proj.ErrNoProject {
return nil, &gqlerror.Error{
Path: graphql.GetPath(ctx),
Message: "No active project.",
Extensions: map[string]interface{}{
"code": "no_active_project",
},
}
return nil, noActiveProjectErr(ctx)
}
if err != nil {
return nil, fmt.Errorf("could not query repository for requests: %v", err)
Expand Down Expand Up @@ -268,7 +262,11 @@ func (r *mutationResolver) SetHTTPRequestLogFilter(
if err != nil {
return nil, fmt.Errorf("could not parse request log filter: %v", err)
}
if err := r.RequestLogService.SetRequestLogFilter(ctx, filter); err != nil {
err = r.RequestLogService.SetRequestLogFilter(ctx, filter)
if err == proj.ErrNoProject {
return nil, noActiveProjectErr(ctx)
}
if err != nil {
return nil, fmt.Errorf("could not set request log filter: %v", err)
}

Expand Down Expand Up @@ -331,3 +329,13 @@ func findReqFilterToHTTPReqLogFilter(findReqFilter reqlog.FindRequestsFilter) *H

return httpReqLogFilter
}

func noActiveProjectErr(ctx context.Context) error {
return &gqlerror.Error{
Path: graphql.GetPath(ctx),
Message: "No active project.",
Extensions: map[string]interface{}{
"code": "no_active_project",
},
}
}

0 comments on commit ad3fa7d

Please sign in to comment.