bugfix: postman empty body options

This commit is contained in:
buyuxiang
2022-05-25 09:45:49 +08:00
parent 957f49b367
commit fc59a74b50
2 changed files with 10 additions and 6 deletions

View File

@@ -29,7 +29,6 @@ var har2caseCmd = &cobra.Command{
} }
if flagCount > 1 { if flagCount > 1 {
return errors.New("please specify at most one conversion flag") return errors.New("please specify at most one conversion flag")
} }
convert.Run(har2caseOutputType, har2caseOutputDir, har2caseProfilePath, args) convert.Run(har2caseOutputType, har2caseOutputDir, har2caseProfilePath, args)
return nil return nil

View File

@@ -427,14 +427,19 @@ func (s *stepFromPostman) makeRequestBody(item *TItem, steps []*hrp.TStep) error
func (s *stepFromPostman) makeRequestBodyRaw(item *TItem) (err error) { func (s *stepFromPostman) makeRequestBodyRaw(item *TItem) (err error) {
defer func() { defer func() {
if p := recover(); p != nil { if p := recover(); p != nil {
err = fmt.Errorf("make request body raw failed: %v", p) err = fmt.Errorf("make request body (raw) failed: %v", p)
} }
}() }()
// extract language type // extract language type, default languageType: text
languageType := "text"
iOptions := item.Request.Body.Options iOptions := item.Request.Body.Options
iLanguage := iOptions.(map[string]interface{})["raw"] if iOptions != nil {
languageType := iLanguage.(map[string]interface{})["language"].(string) iLanguage := iOptions.(map[string]interface{})["raw"]
if iLanguage != nil {
languageType = iLanguage.(map[string]interface{})["language"].(string)
}
}
// make request body and indicate Content-Type // make request body and indicate Content-Type
rawBody := item.Request.Body.Raw rawBody := item.Request.Body.Raw
@@ -442,7 +447,7 @@ func (s *stepFromPostman) makeRequestBodyRaw(item *TItem) (err error) {
var iBody interface{} var iBody interface{}
err = json.Unmarshal([]byte(rawBody), &iBody) err = json.Unmarshal([]byte(rawBody), &iBody)
if err != nil { if err != nil {
return errors.Wrap(err, "make request body raw failed") return errors.Wrap(err, "make request body (raw -> json) failed")
} }
s.Request.Body = iBody s.Request.Body = iBody
} else { } else {