Handle req log filter I/O when no project is set

This commit is contained in:
David Stotijn 2020-12-29 20:46:42 +01:00
parent 8c2efdb285
commit ad3fa7d379
2 changed files with 18 additions and 9 deletions

View file

@ -89,7 +89,7 @@ function Search(): JSX.Element {
FILTER, FILTER,
{ {
onCompleted: (data) => { onCompleted: (data) => {
setSearchExpr(data.httpRequestLogFilter.searchExpression || ""); setSearchExpr(data.httpRequestLogFilter?.searchExpression || "");
}, },
} }
); );
@ -108,6 +108,7 @@ function Search(): JSX.Element {
}, },
}); });
}, },
onError: () => {},
}); });
const [ const [

View file

@ -31,13 +31,7 @@ func (r *Resolver) Mutation() MutationResolver { return &mutationResolver{r} }
func (r *queryResolver) HTTPRequestLogs(ctx context.Context) ([]HTTPRequestLog, error) { func (r *queryResolver) HTTPRequestLogs(ctx context.Context) ([]HTTPRequestLog, error) {
reqs, err := r.RequestLogService.FindRequests(ctx) reqs, err := r.RequestLogService.FindRequests(ctx)
if err == proj.ErrNoProject { if err == proj.ErrNoProject {
return nil, &gqlerror.Error{ return nil, noActiveProjectErr(ctx)
Path: graphql.GetPath(ctx),
Message: "No active project.",
Extensions: map[string]interface{}{
"code": "no_active_project",
},
}
} }
if err != nil { if err != nil {
return nil, fmt.Errorf("could not query repository for requests: %v", err) return nil, fmt.Errorf("could not query repository for requests: %v", err)
@ -268,7 +262,11 @@ func (r *mutationResolver) SetHTTPRequestLogFilter(
if err != nil { if err != nil {
return nil, fmt.Errorf("could not parse request log filter: %v", err) 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) return nil, fmt.Errorf("could not set request log filter: %v", err)
} }
@ -331,3 +329,13 @@ func findReqFilterToHTTPReqLogFilter(findReqFilter reqlog.FindRequestsFilter) *H
return httpReqLogFilter 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",
},
}
}