Skip to content

Commit

Permalink
fix panic when export as oav
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-henglu committed Aug 17, 2023
1 parent ecb3af2 commit 45c297b
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions formatter/oav_traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,35 @@ type LiveResponse struct {

func (o OavTrafficFormatter) Format(r types.RequestTrace) string {
var requestBody interface{}
err := json.Unmarshal([]byte(r.Request.Body), &requestBody)
if err != nil {
requestBody = nil
requestHeaders := make(map[string]string)
if r.Request != nil {
err := json.Unmarshal([]byte(r.Request.Body), &requestBody)
if err != nil {
requestBody = nil
}
requestHeaders = r.Request.Headers
}

var responseBody interface{}
err = json.Unmarshal([]byte(r.Response.Body), &responseBody)
if err != nil {
responseBody = nil
responseHeaders := make(map[string]string)
if r.Response != nil {
err := json.Unmarshal([]byte(r.Response.Body), &responseBody)
if err != nil {
responseBody = nil
}
responseHeaders = r.Response.Headers
}

out := OavTraffic{
LiveRequest: LiveRequest{
Headers: r.Request.Headers,
Headers: requestHeaders,
Method: r.Method,
Url: r.Url,
Body: requestBody,
},
LiveResponse: LiveResponse{
StatusCode: fmt.Sprintf("%d", r.StatusCode),
Headers: r.Response.Headers,
Headers: responseHeaders,
Body: responseBody,
},
}
Expand Down

0 comments on commit 45c297b

Please sign in to comment.