Skip to content

MarshalResponse maybe panic #26

Description

@wen313
func MarshalResponse(msg []byte) (Response, error) {
	var j map[string]interface{}

	err := jsonUnmarshal(msg, &j)
	if err != nil {
		return Response{}, gremerror.NewUnmarshalError("MarshalResponse", msg, err)
	}

	var (
		status = j["status"].(map[string]interface{})
		result = j["result"].(map[string]interface{})
		code   = status["code"].(float64)
		resp   = Response{Code: int(code)}
	)

	err = responseDetectError(resp.Code)
	if err != nil {
		resp.Data = err // Use the Data field as a vehicle for the error.
	} else {
		resp.Data = result["data"]
	}
	resp.RequestID = j["requestId"].(string)

	return resp, nil
}

resp.RequestID = j["requestId"].(string) maybe cause panic,panic message:
interface conversion: interface {} is nil, not string

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions