Use errRes status instead of res

This commit is contained in:
some 2024-10-01 22:11:35 -04:00
parent fe10226ab2
commit b62fecf362
Signed by: some
GPG Key ID: 65D0589220B9BFC8
3 changed files with 1 additions and 17 deletions

View File

@ -92,14 +92,9 @@ func (cr *CallbackRequest) Parse(data *url.Values) (err error) {
} }
type CallbackResponse struct { type CallbackResponse struct {
Status int `json:"-"`
Message string `json:"message"` Message string `json:"message"`
} }
func (cr *CallbackResponse) HttpStatus() (code int) {
return cr.Status
}
func (cr *CallbackResponse) Response() []byte { func (cr *CallbackResponse) Response() []byte {
return mustMarshalJson(cr) return mustMarshalJson(cr)
} }

View File

@ -16,7 +16,6 @@ type EmptyRequest interface {
} }
type Response interface { type Response interface {
HttpStatus() int
Response() []byte Response() []byte
} }
@ -71,11 +70,6 @@ func (srv *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Write(errRes.ErrorResponse()) w.Write(errRes.ErrorResponse())
srv.logger.Logf(log.LevelError, "request failed: %s", errRes.String()) srv.logger.Logf(log.LevelError, "request failed: %s", errRes.String())
} }
if res.HttpStatus() >= 100 { w.WriteHeader(errRes.HttpStatus())
w.WriteHeader(res.HttpStatus())
} else {
w.WriteHeader(http.StatusInternalServerError)
srv.logger.Logf(log.LevelError, "received invalid status from service (%d)", res.HttpStatus())
}
w.Write(res.Response()) w.Write(res.Response())
} }

View File

@ -108,7 +108,6 @@ func (tr *TokenRequest) Parse(data *url.Values) (err error) {
} }
type TokenResponse struct { type TokenResponse struct {
Status int `json:"-"`
VerificationUri string `json:"verification_uri"` VerificationUri string `json:"verification_uri"`
UserCode session.Code `json:"user_code"` UserCode session.Code `json:"user_code"`
DeviceCode session.Code `json:"device_code"` DeviceCode session.Code `json:"device_code"`
@ -116,10 +115,6 @@ type TokenResponse struct {
ExpiresIn int `json:"expires_in"` ExpiresIn int `json:"expires_in"`
} }
func (tr *TokenResponse) HttpStatus() (code int) {
return tr.Status
}
func (tr *TokenResponse) Response() []byte { func (tr *TokenResponse) Response() []byte {
return mustMarshalJson(tr) return mustMarshalJson(tr)
} }