Skip to content

Commit d3b564c

Browse files
with []graphqlError
1 parent 29152eb commit d3b564c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pkg/codefresh/argo_runtime.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ type (
2727
Data struct {
2828
Runtime model.RuntimeCreationResponse
2929
}
30+
Errors []graphqlError
3031
}
3132
)
3233

3334
func newArgoRuntimeAPI(codefresh *codefresh) IArgoRuntimeAPI {
3435
return &argoRuntime{codefresh: codefresh}
3536
}
3637

37-
func (r *argoRuntime) Create(runtimeName string) (*model.RuntimeCreationResponse, error) { // TODO: should also return error
38+
func (r *argoRuntime) Create(runtimeName string) (*model.RuntimeCreationResponse, error) {
3839
type forJsonData interface{}
3940

4041
// the newlines are necessary
@@ -61,13 +62,17 @@ func (r *argoRuntime) Create(runtimeName string) (*model.RuntimeCreationResponse
6162
fmt.Printf("failed to read from response body")
6263
return nil, err
6364
}
64-
res := graphQlRuntimeCreationResponse{}
6565

66+
res := graphQlRuntimeCreationResponse{}
6667
err = json.Unmarshal(data, &res)
6768
if err != nil {
6869
return nil, err
6970
}
7071

72+
if len(res.Errors) > 0 {
73+
return nil, graphqlErrorResponse{errors: res.Errors}
74+
}
75+
7176
return &res.Data.Runtime, nil
7277
}
7378

@@ -112,11 +117,14 @@ func (r *argoRuntime) List() ([]model.Runtime, error) {
112117
fmt.Printf("failed to read from response body")
113118
return nil, err
114119
}
120+
115121
res := graphqlRuntimesResponse{}
116122
err = json.Unmarshal(data, &res)
123+
117124
if err != nil {
118125
return nil, err
119126
}
127+
120128
runtimes := make([]model.Runtime, len(res.Data.Runtimes.Edges))
121129
for i := range res.Data.Runtimes.Edges {
122130
runtimes[i] = *res.Data.Runtimes.Edges[i].Node
@@ -127,5 +135,4 @@ func (r *argoRuntime) List() ([]model.Runtime, error) {
127135
}
128136

129137
return runtimes, nil
130-
131138
}

0 commit comments

Comments
 (0)