Skip to content

Commit

Permalink
fix(backend): fixing response status code for grpc request (#2741)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoscar committed Jun 16, 2023
1 parent 4bb77e5 commit 887b34c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
3 changes: 3 additions & 0 deletions api/grpc.yaml
Expand Up @@ -31,9 +31,12 @@ components:

GRPCResponse:
type: object
required:
- statusCode
properties:
statusCode:
type: integer
default: 0
metadata:
type: array
items:
Expand Down
37 changes: 15 additions & 22 deletions cli/openapi/model_grpc_response.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion server/openapi/model_grpc_response.go
Expand Up @@ -10,7 +10,7 @@
package openapi

type GrpcResponse struct {
StatusCode int32 `json:"statusCode,omitempty"`
StatusCode int32 `json:"statusCode"`

Metadata []GrpcHeader `json:"metadata,omitempty"`

Expand All @@ -19,6 +19,15 @@ type GrpcResponse struct {

// AssertGrpcResponseRequired checks if the required fields are not zero-ed
func AssertGrpcResponseRequired(obj GrpcResponse) error {
elements := map[string]interface{}{
"statusCode": obj.StatusCode,
}
for name, el := range elements {
if isZero := IsZeroValue(el); isZero {
return &RequiredError{Field: name}
}
}

for _, el := range obj.Metadata {
if err := AssertGrpcHeaderRequired(el); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions web/src/models/TriggerResult.model.ts
Expand Up @@ -24,7 +24,7 @@ const ResponseData = {
return {
body: get(response, 'body', ''),
headers: get(response, 'metadata', undefined) as THeader[],
statusCode: get(response, 'statusCode', 200),
statusCode: get(response, 'statusCode', 0),
};
},
[TriggerTypes.traceid](response: object) {
Expand All @@ -38,7 +38,7 @@ const ResponseData = {

const TriggerResult = ({
triggerType = 'http',
triggerResult: {http = {}, grpc = {}, traceid = {}} = {},
triggerResult: {http = {}, grpc = {statusCode: 0}, traceid = {}} = {},
}: TRawTriggerResult): TriggerResult => {
const type = triggerType as TriggerTypes;

Expand Down
2 changes: 1 addition & 1 deletion web/src/types/Generated.types.ts
Expand Up @@ -1565,7 +1565,7 @@ export interface external {
request?: string;
};
GRPCResponse: {
statusCode?: number;
statusCode: number;
metadata?: external["grpc.yaml"]["components"]["schemas"]["GRPCHeader"][];
body?: string;
};
Expand Down

0 comments on commit 887b34c

Please sign in to comment.