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

unierr: Is it necessary to allow err is nil? #125

Closed
GGXXLL opened this issue Apr 26, 2021 · 1 comment
Closed

unierr: Is it necessary to allow err is nil? #125

GGXXLL opened this issue Apr 26, 2021 · 1 comment

Comments

@GGXXLL
Copy link
Contributor

GGXXLL commented Apr 26, 2021

Now, unierr.InvalidArgumentErr(nil) will panic. Hope allow err is nil. Is it necessary? such as:

func (h *Handler) Find(writer http.ResponseWriter, request *http.Request) {
	encoder := srvhttp.NewResponseEncoder(writer)
	id := request.URL.Query().Get("id")
	if id == "" {
		// return {"code":3,"message":"InvalidArgumentErr"}
		// unierr.InvalidArgumentErr(nil)

		// return {"code":3,"message":"id is required"}
		// unierr.InvalidArgumentErr(nil, "id is required")

		// return {"code":3,"message":"id is required"}
		encoder.EncodeError(unierr.InvalidArgumentErr(nil,"id is required"))
		return
	}
	m := map[string]interface{}{}
	h.gorm.Table("track").Where("id=?", id).Order("id desc").Find(&m)

	encoder.EncodeResponse(m)
}
@Reasno
Copy link
Member

Reasno commented Apr 26, 2021

I think it is reasonable to allow nil errors.

@Reasno Reasno closed this as completed in 6c3f812 Apr 27, 2021
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