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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions