Closed harshkhandeparkar closed 1 year ago
@Alph3ga @YoganshSharma do you have any suggestions for this?
How about adding a response struct similar to this
type HTTPError struct {
Code int `json:"code" example:"400"`
Message string `json:"message" example:"status bad request"`
}
And refactoring utils.LogWarnAndRespond
and utils.LogErrAndRespond
to use this instead.
Some places where these util functions should be used, but they aren't. That also needs to be fixed.
How about adding a response struct similar to this
type HTTPError struct { Code int `json:"code" example:"400"` Message string `json:"message" example:"status bad request"` }
Works.
And refactoring
utils.LogWarnAndRespond
andutils.LogErrAndRespond
to use this instead. Some places where these util functions should be used, but they aren't. That also needs to be fixed.
Which places? (apart from #130 ?)
ig we should generalize HTTPError
to a more general name like HTTPMessage
and use it wherever we are return status code 200 and a message
like https://github.com/kossiitkgp/KWoC-Backend/blob/00662b266ce2b7cd487a1880efd9fb0dc7c206ee/controllers/mentor.go#L87-L88
Interesting
do you want to work on this? self assign if yes. also ig doing this before #150 would be better
Currently, the format of the responses returned by endpoints is not standard. In some cases, a plain text response is returned, whereas in some cases, it is JSON. Also, the text in the response is different. (For example, there is no standard format for error responses)
A standard JSON format would be better for responses of every endpoint. Please share any ideas below.