mirror of
https://gitee.com/zhangsken/aliyunpan.git
synced 2026-10-16 02:23:49 +08:00
handle api common error
This commit is contained in:
@@ -14,7 +14,7 @@ require (
|
|||||||
github.com/olekukonko/tablewriter v0.0.2-0.20190618033246-cc27d85e17ce
|
github.com/olekukonko/tablewriter v0.0.2-0.20190618033246-cc27d85e17ce
|
||||||
github.com/peterh/liner v1.2.1
|
github.com/peterh/liner v1.2.1
|
||||||
github.com/satori/go.uuid v1.2.0
|
github.com/satori/go.uuid v1.2.0
|
||||||
github.com/tickstep/aliyunpan-api v0.2.6
|
github.com/tickstep/aliyunpan-api v0.2.7
|
||||||
github.com/tickstep/bolt v1.3.4
|
github.com/tickstep/bolt v1.3.4
|
||||||
github.com/tickstep/library-go v0.1.3
|
github.com/tickstep/library-go v0.1.3
|
||||||
github.com/urfave/cli v1.21.1-0.20190817182405-23c83030263f
|
github.com/urfave/cli v1.21.1-0.20190817182405-23c83030263f
|
||||||
|
|||||||
@@ -101,8 +101,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
|
|||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/tickstep/aliyunpan-api v0.2.6 h1:cjn+bBLcPbquKV80aXv07a7808csWche5ctZ4yLljso=
|
github.com/tickstep/aliyunpan-api v0.2.7 h1:Ot6xLobZxw6Xr+NmO25Ogl50J/NxFghx7K+j+q+ybQE=
|
||||||
github.com/tickstep/aliyunpan-api v0.2.6/go.mod h1:UvQgQYMIgA5k1QsfKIVnEJ2h/HqDXIkAb16oookNc8o=
|
github.com/tickstep/aliyunpan-api v0.2.7/go.mod h1:UvQgQYMIgA5k1QsfKIVnEJ2h/HqDXIkAb16oookNc8o=
|
||||||
github.com/tickstep/bolt v1.3.4 h1:UN1txRsauOfR8a5mUWm5So0ng233PsIMVR5/+3WowCE=
|
github.com/tickstep/bolt v1.3.4 h1:UN1txRsauOfR8a5mUWm5So0ng233PsIMVR5/+3WowCE=
|
||||||
github.com/tickstep/bolt v1.3.4/go.mod h1:Y24RwCywbOsKAyHiVcJ4K2QQfED+q67x7PEOH9OG7Q4=
|
github.com/tickstep/bolt v1.3.4/go.mod h1:Y24RwCywbOsKAyHiVcJ4K2QQfED+q67x7PEOH9OG7Q4=
|
||||||
github.com/tickstep/library-go v0.1.3 h1:OUj6nkimTsqhHXh5s+PbmHq5hR0m739Y1tu9QpfA2ng=
|
github.com/tickstep/library-go v0.1.3 h1:OUj6nkimTsqhHXh5s+PbmHq5hR0m739Y1tu9QpfA2ng=
|
||||||
|
|||||||
@@ -21,6 +21,12 @@ type LoginHelper struct {
|
|||||||
webHost string
|
webHost string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 通用接口错误
|
||||||
|
type respCommonResult struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
|
}
|
||||||
|
|
||||||
type LoginHttpResult struct {
|
type LoginHttpResult struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
@@ -86,6 +92,16 @@ func (h *LoginHelper) GetQRCodeLoginUrl(keyStr string) (*QRCodeUrlResult, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 通用接口错误
|
||||||
|
commonResult := &respCommonResult{}
|
||||||
|
if err1 := json.Unmarshal(body, commonResult); err1 != nil {
|
||||||
|
logger.Verboseln("parse openapi result json error ", err1)
|
||||||
|
return nil, err1
|
||||||
|
}
|
||||||
|
if commonResult.Code != 0 {
|
||||||
|
return nil, fmt.Errorf(commonResult.Msg)
|
||||||
|
}
|
||||||
|
|
||||||
errResp := &LoginHttpResult{}
|
errResp := &LoginHttpResult{}
|
||||||
if err1 := json.Unmarshal(body, errResp); err1 != nil {
|
if err1 := json.Unmarshal(body, errResp); err1 != nil {
|
||||||
logger.Verboseln("parse qrcode result json error ", err1)
|
logger.Verboseln("parse qrcode result json error ", err1)
|
||||||
@@ -137,6 +153,16 @@ func (h *LoginHelper) GetQRCodeLoginResult(tokenId string) (*QRCodeLoginResult,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 通用接口错误
|
||||||
|
commonResult := &respCommonResult{}
|
||||||
|
if err1 := json.Unmarshal(body, commonResult); err1 != nil {
|
||||||
|
logger.Verboseln("parse openapi result json error ", err1)
|
||||||
|
return nil, err1
|
||||||
|
}
|
||||||
|
if commonResult.Code != 0 {
|
||||||
|
return nil, fmt.Errorf(commonResult.Msg)
|
||||||
|
}
|
||||||
|
|
||||||
errResp := &LoginHttpResult{}
|
errResp := &LoginHttpResult{}
|
||||||
if err1 := json.Unmarshal(body, errResp); err1 != nil {
|
if err1 := json.Unmarshal(body, errResp); err1 != nil {
|
||||||
logger.Verboseln("parse qrcode result json error ", err1)
|
logger.Verboseln("parse qrcode result json error ", err1)
|
||||||
@@ -177,6 +203,16 @@ func (h *LoginHelper) GetRefreshToken(tokenId string) (*QRCodeLoginResult, error
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 通用接口错误
|
||||||
|
commonResult := &respCommonResult{}
|
||||||
|
if err1 := json.Unmarshal(body, commonResult); err1 != nil {
|
||||||
|
logger.Verboseln("parse openapi result json error ", err1)
|
||||||
|
return nil, err1
|
||||||
|
}
|
||||||
|
if commonResult.Code != 0 {
|
||||||
|
return nil, fmt.Errorf(commonResult.Msg)
|
||||||
|
}
|
||||||
|
|
||||||
errResp := &LoginHttpResult{}
|
errResp := &LoginHttpResult{}
|
||||||
if err1 := json.Unmarshal(body, errResp); err1 != nil {
|
if err1 := json.Unmarshal(body, errResp); err1 != nil {
|
||||||
logger.Verboseln("parse qrcode result json error ", err1)
|
logger.Verboseln("parse qrcode result json error ", err1)
|
||||||
@@ -254,6 +290,16 @@ func (h *LoginHelper) GetWebapiNewToken(ticketId, userId, oldAccessToken string)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 通用接口错误
|
||||||
|
commonResult := &respCommonResult{}
|
||||||
|
if err1 := json.Unmarshal(body, commonResult); err1 != nil {
|
||||||
|
logger.Verboseln("parse openapi result json error ", err1)
|
||||||
|
return nil, err1
|
||||||
|
}
|
||||||
|
if commonResult.Code != 0 {
|
||||||
|
return nil, fmt.Errorf(commonResult.Msg)
|
||||||
|
}
|
||||||
|
|
||||||
errResp := &LoginHttpResult{}
|
errResp := &LoginHttpResult{}
|
||||||
if err1 := json.Unmarshal(body, errResp); err1 != nil {
|
if err1 := json.Unmarshal(body, errResp); err1 != nil {
|
||||||
logger.Verboseln("parse result json error ", err1)
|
logger.Verboseln("parse result json error ", err1)
|
||||||
@@ -295,6 +341,17 @@ func (h *LoginHelper) GetOpenapiNewToken(ticketId, userId, oldAccessToken string
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 通用接口错误
|
||||||
|
commonResult := &respCommonResult{}
|
||||||
|
if err1 := json.Unmarshal(body, commonResult); err1 != nil {
|
||||||
|
logger.Verboseln("parse openapi result json error ", err1)
|
||||||
|
return nil, err1
|
||||||
|
}
|
||||||
|
if commonResult.Code != 0 {
|
||||||
|
return nil, fmt.Errorf(commonResult.Msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析结果
|
||||||
errResp := &LoginHttpResult{}
|
errResp := &LoginHttpResult{}
|
||||||
if err1 := json.Unmarshal(body, errResp); err1 != nil {
|
if err1 := json.Unmarshal(body, errResp); err1 != nil {
|
||||||
logger.Verboseln("parse result json error ", err1)
|
logger.Verboseln("parse result json error ", err1)
|
||||||
@@ -335,6 +392,16 @@ func (h *LoginHelper) GetLoginToken(ticketId string) (*CommonTokenEntity, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 通用接口错误
|
||||||
|
commonResult := &respCommonResult{}
|
||||||
|
if err1 := json.Unmarshal(body, commonResult); err1 != nil {
|
||||||
|
logger.Verboseln("parse openapi result json error ", err1)
|
||||||
|
return nil, err1
|
||||||
|
}
|
||||||
|
if commonResult.Code != 0 {
|
||||||
|
return nil, fmt.Errorf(commonResult.Msg)
|
||||||
|
}
|
||||||
|
|
||||||
errResp := &LoginHttpResult{}
|
errResp := &LoginHttpResult{}
|
||||||
if err1 := json.Unmarshal(body, errResp); err1 != nil {
|
if err1 := json.Unmarshal(body, errResp); err1 != nil {
|
||||||
logger.Verboseln("parse result json error ", err1)
|
logger.Verboseln("parse result json error ", err1)
|
||||||
|
|||||||
Reference in New Issue
Block a user