Преглед изворни кода

modify decoder error to include parsing details

Alexander Belanger пре 4 година
родитељ
комит
b121af669c

+ 1 - 1
api/server/shared/requestutils/decoder.go

@@ -70,7 +70,7 @@ func requestErrorFromJSONErr(err error) apierrors.RequestError {
 	} else if errors.As(err, &typeErr) {
 		clientErr = fmt.Errorf("Invalid type for body param %s: expected %s, got %s", typeErr.Field, typeErr.Type.Kind().String(), typeErr.Value)
 	} else {
-		clientErr = fmt.Errorf("Could not parse JSON request")
+		clientErr = fmt.Errorf("Could not parse JSON request: %s", err.Error())
 	}
 
 	return apierrors.NewErrPassThroughToClient(clientErr, http.StatusBadRequest)

+ 1 - 1
api/server/shared/requestutils/decoder_test.go

@@ -32,7 +32,7 @@ type decoderTestObj struct {
 const (
 	jsonFieldErrFmt  = "Invalid type for body param %s: expected %s, got %s"
 	jsonSyntaxErrFmt = "JSON syntax error at character %d"
-	jsonGenericErr   = "Could not parse JSON request"
+	jsonGenericErr   = "Could not parse JSON request: unexpected EOF"
 )
 
 func getSuccessfulJSONBody() io.ReadCloser {