🎨 updated error handling logic

This commit is contained in:
landaiqing
2024-11-18 01:12:50 +08:00
parent 78a162a19a
commit 35d2da35b2
48 changed files with 395 additions and 170 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/common/response"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
)
@@ -16,7 +17,11 @@ func GetGiteeOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
resp, err := l.GetGiteeOauthUrl()
if err != nil {
logx.Error(err)
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
httpx.WriteJsonCtx(
r.Context(),
w,
http.StatusInternalServerError,
response.ErrorWithI18n(r.Context(), "system.error"))
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}

View File

@@ -6,6 +6,7 @@ import (
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/common/response"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
"schisandra-album-cloud-microservices/app/core/api/internal/types"
@@ -23,7 +24,11 @@ func GetGithubOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
resp, err := l.GetGithubOauthUrl(&req)
if err != nil {
logx.Error(err)
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
httpx.WriteJsonCtx(
r.Context(),
w,
http.StatusInternalServerError,
response.ErrorWithI18n(r.Context(), "system.error"))
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}

View File

@@ -6,6 +6,7 @@ import (
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/common/response"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
"schisandra-album-cloud-microservices/app/core/api/internal/types"
@@ -23,7 +24,11 @@ func GetQqOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
resp, err := l.GetQqOauthUrl(&req)
if err != nil {
logx.Error(err)
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
httpx.WriteJsonCtx(
r.Context(),
w,
http.StatusInternalServerError,
response.ErrorWithI18n(r.Context(), "system.error"))
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}

View File

@@ -6,6 +6,7 @@ import (
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/common/response"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
"schisandra-album-cloud-microservices/app/core/api/internal/types"
@@ -23,7 +24,11 @@ func GetWechatQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
resp, err := l.GetWechatQrcode(r, &req)
if err != nil {
logx.Error(err)
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
httpx.WriteJsonCtx(
r.Context(),
w,
http.StatusInternalServerError,
response.ErrorWithI18n(r.Context(), "system.error"))
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}

View File

@@ -1,12 +1,12 @@
package oauth
import (
"errors"
"net/http"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/common/response"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
"schisandra-album-cloud-microservices/app/core/api/internal/types"
@@ -24,7 +24,11 @@ func GiteeCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
err := l.GiteeCallback(w, r, &req)
if err != nil {
logx.Error(err)
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
httpx.WriteJsonCtx(
r.Context(),
w,
http.StatusInternalServerError,
response.ErrorWithI18n(r.Context(), "system.error"))
} else {
httpx.Ok(w)
}

View File

@@ -1,12 +1,12 @@
package oauth
import (
"errors"
"net/http"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/common/response"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
"schisandra-album-cloud-microservices/app/core/api/internal/types"
@@ -24,7 +24,11 @@ func GithubCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
err := l.GithubCallback(w, r, &req)
if err != nil {
logx.Error(err)
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
httpx.WriteJsonCtx(
r.Context(),
w,
http.StatusInternalServerError,
response.ErrorWithI18n(r.Context(), "system.error"))
} else {
httpx.Ok(w)
}

View File

@@ -1,12 +1,12 @@
package oauth
import (
"errors"
"net/http"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/common/response"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
"schisandra-album-cloud-microservices/app/core/api/internal/types"
@@ -24,7 +24,11 @@ func QqCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
err := l.QqCallback(w, r, &req)
if err != nil {
logx.Error(err)
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
httpx.WriteJsonCtx(
r.Context(),
w,
http.StatusInternalServerError,
response.ErrorWithI18n(r.Context(), "system.error"))
} else {
httpx.Ok(w)
}

View File

@@ -1,12 +1,12 @@
package oauth
import (
"errors"
"net/http"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/common/response"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
)
@@ -17,7 +17,11 @@ func WechatCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
err := l.WechatCallback(w, r)
if err != nil {
logx.Error(err)
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
httpx.WriteJsonCtx(
r.Context(),
w,
http.StatusInternalServerError,
response.ErrorWithI18n(r.Context(), "system.error"))
} else {
httpx.Ok(w)
}