From 9190db10990a8330790efb37ca92e8226e9dbcc6 Mon Sep 17 00:00:00 2001 From: DacongDA Date: Tue, 20 May 2025 10:39:55 +0800 Subject: [PATCH] feat: fix bug that token endpoint doesn't return 400/401 when type is object.TokenError (#3808) --- controllers/token.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/controllers/token.go b/controllers/token.go index de813fa6..176aa04e 100644 --- a/controllers/token.go +++ b/controllers/token.go @@ -224,10 +224,11 @@ func (c *ApiController) GetOAuthToken() { if deviceCode != "" { deviceAuthCache, ok := object.DeviceAuthMap.Load(deviceCode) if !ok { - c.Data["json"] = object.TokenError{ + c.Data["json"] = &object.TokenError{ Error: "expired_token", ErrorDescription: "token is expired", } + c.SetTokenErrorHttpStatus() c.ServeJSON() c.SetTokenErrorHttpStatus() return @@ -235,20 +236,22 @@ func (c *ApiController) GetOAuthToken() { deviceAuthCacheCast := deviceAuthCache.(object.DeviceAuthCache) if !deviceAuthCacheCast.UserSignIn { - c.Data["json"] = object.TokenError{ + c.Data["json"] = &object.TokenError{ Error: "authorization_pending", ErrorDescription: "authorization pending", } + c.SetTokenErrorHttpStatus() c.ServeJSON() c.SetTokenErrorHttpStatus() return } if deviceAuthCacheCast.RequestAt.Add(time.Second * 120).Before(time.Now()) { - c.Data["json"] = object.TokenError{ + c.Data["json"] = &object.TokenError{ Error: "expired_token", ErrorDescription: "token is expired", } + c.SetTokenErrorHttpStatus() c.ServeJSON() c.SetTokenErrorHttpStatus() return