Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MarshalResponse maybe panic #26

Open
wen313 opened this issue Jul 1, 2020 · 1 comment
Open

MarshalResponse maybe panic #26

wen313 opened this issue Jul 1, 2020 · 1 comment

Comments

@wen313
Copy link

wen313 commented Jul 1, 2020

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

@AdallomRoy
Copy link

I can happen when your request is too long (larger than the gorilla buffer, 8192 bytes I think) and the request is split. In that case the server doesn't see the request ID so in the response it doesn't send one.
The current solution is to increase the request buffer, or make your request smaller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants