Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimized-error-handling&remove unused constant #772

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions miniprogram/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,8 @@ func (auth *Auth) GetPhoneNumberContext(ctx context2.Context, code string) (*Get
}

var result GetPhoneNumberResponse
if err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber"); err != nil {
return nil, err
}
return &result, nil
err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber")
return &result, err
}

// GetPhoneNumber 小程序通过code获取用户手机号
Expand Down
7 changes: 1 addition & 6 deletions miniprogram/business/phone_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,5 @@ func (business *Business) GetPhoneNumber(in *GetPhoneNumberRequest) (info PhoneI
PhoneInfo PhoneInfo `json:"phone_info"`
}
err = util.DecodeWithError(response, &resp, "business.GetPhoneNumber")
if nil != err {
return
}

info = resp.PhoneInfo
return
return resp.PhoneInfo, err
}
18 changes: 4 additions & 14 deletions miniprogram/privacy/privacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,8 @@ func (s *Privacy) GetPrivacySetting(privacyVer int) (GetPrivacySettingResponse,
}
// 返回错误信息
var result GetPrivacySettingResponse
if err = util.DecodeWithError(response, &result, "getprivacysetting"); err != nil {
return GetPrivacySettingResponse{}, err
}

return result, nil
err = util.DecodeWithError(response, &result, "getprivacysetting")
return result, err
}

// SetPrivacySetting 更新小程序权限配置
Expand All @@ -130,11 +127,7 @@ func (s *Privacy) SetPrivacySetting(privacyVer int, ownerSetting OwnerSetting, s
}

// 返回错误信息
if err = util.DecodeWithCommonError(response, "setprivacysetting"); err != nil {
return err
}

return err
return util.DecodeWithCommonError(response, "setprivacysetting")
}

// UploadPrivacyExtFileResponse 上传权限定义模板响应参数
Expand All @@ -159,9 +152,6 @@ func (s *Privacy) UploadPrivacyExtFile(fileData []byte) (UploadPrivacyExtFileRes

// 返回错误信息
var result UploadPrivacyExtFileResponse
if err = util.DecodeWithError(response, &result, "setprivacysetting"); err != nil {
return UploadPrivacyExtFileResponse{}, err
}

err = util.DecodeWithError(response, &result, "setprivacysetting")
return result, err
}
14 changes: 2 additions & 12 deletions miniprogram/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ func (security *Security) MediaCheckAsyncV1(in *MediaCheckAsyncV1Request) (trace
TraceID string `json:"trace_id"`
}
err = util.DecodeWithError(response, &res, "MediaCheckAsyncV1")
if err != nil {
return
}

traceID = res.TraceID
return
return res.TraceID, err
}

// MediaCheckAsyncRequest 图片/音频异步校验请求参数
Expand Down Expand Up @@ -93,12 +88,7 @@ func (security *Security) MediaCheckAsync(in *MediaCheckAsyncRequest) (traceID s
TraceID string `json:"trace_id"`
}
err = util.DecodeWithError(response, &res, "MediaCheckAsync")
if err != nil {
return
}

traceID = res.TraceID
return
return res.TraceID, err
}

// ImageCheckV1 校验一张图片是否含有违法违规内容(同步)
Expand Down
6 changes: 1 addition & 5 deletions miniprogram/shortlink/shortlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ func (shortLink *ShortLink) generate(shortLinkParams ShortLinker) (string, error
// 使用通用方法返回错误
var res resShortLinker
err = util.DecodeWithError(response, &res, "GenerateShortLink")
if err != nil {
return "", err
}

return res.Link, nil
return res.Link, err
}

// GenerateShortLinkPermanent 生成永久 shortLink
Expand Down
6 changes: 1 addition & 5 deletions miniprogram/subscribe/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,7 @@ func (s *Subscribe) Add(ShortID string, kidList []int, sceneDesc string) (templa
}
var result resSubscribeAdd
err = util.DecodeWithError(response, &result, "AddSubscribe")
if err != nil {
return
}
templateID = result.TemplateID
return
return result.TemplateID, err
}

// Delete 删除私有模板
Expand Down
5 changes: 1 addition & 4 deletions miniprogram/urllink/urllink.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,5 @@ func (u *URLLink) Generate(params *ULParams) (string, error) {
}
var resp ULResult
err = util.DecodeWithError(response, &resp, "URLLink.Generate")
if err != nil {
return "", err
}
return resp.URLLink, nil
return resp.URLLink, err
}
6 changes: 1 addition & 5 deletions miniprogram/urlscheme/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,5 @@ func (u *URLScheme) QueryScheme(querySchemeParams QueryScheme) (schemeInfo Schem
// 使用通用方法返回错误
var res resQueryScheme
err = util.DecodeWithError(response, &res, "QueryScheme")
if err != nil {
return
}

return res.SchemeInfo, res.VisitOpenid, nil
return res.SchemeInfo, res.VisitOpenid, err
}
5 changes: 1 addition & 4 deletions miniprogram/urlscheme/urlscheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,5 @@ func (u *URLScheme) Generate(params *USParams) (string, error) {
}
var resp USResult
err = util.DecodeWithError(response, &resp, "URLScheme.Generate")
if err != nil {
return "", err
}
return resp.OpenLink, nil
return resp.OpenLink, err
}
7 changes: 2 additions & 5 deletions officialaccount/basic/short_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ func (basic *Basic) Long2ShortURL(longURL string) (shortURL string, err error) {
if err != nil {
return
}
if err = util.DecodeWithError(responseBytes, resp, long2shortAction); err != nil {
return
}
shortURL = resp.ShortURL
return
err = util.DecodeWithError(responseBytes, resp, long2shortAction)
return resp.ShortURL, err
}
12 changes: 2 additions & 10 deletions officialaccount/customerservice/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ func (csm *Manager) List() (customerServiceList []*KeFuInfo, err error) {
}
var res resKeFuList
err = util.DecodeWithError(response, &res, "ListCustomerService")
if err != nil {
return
}
customerServiceList = res.KfList
return
return res.KfList, err
}

// KeFuOnlineInfo 客服在线信息
Expand Down Expand Up @@ -107,11 +103,7 @@ func (csm *Manager) OnlineList() (customerServiceOnlineList []*KeFuOnlineInfo, e
}
var res resKeFuOnlineList
err = util.DecodeWithError(response, &res, "ListOnlineCustomerService")
if err != nil {
return
}
customerServiceOnlineList = res.KfOnlineList
return
return res.KfOnlineList, err
}

// Add 添加客服账号
Expand Down
3 changes: 0 additions & 3 deletions officialaccount/datacube/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ func (cube *DataCube) fetchData(params ParamsPublisher) (response []byte, err er
uri := fmt.Sprintf("%s?%s", publisherURL, v.Encode())

response, err = util.HTTPGet(uri)
if err != nil {
return
}
return
}

Expand Down
20 changes: 3 additions & 17 deletions officialaccount/draft/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ func (draft *Draft) AddDraft(articles []*Article) (mediaID string, err error) {
MediaID string `json:"media_id"`
}
err = util.DecodeWithError(response, &res, "AddDraft")
if err != nil {
return
}
mediaID = res.MediaID
return
return res.MediaID, err
}

// GetDraft 获取草稿
Expand All @@ -94,12 +90,7 @@ func (draft *Draft) GetDraft(mediaID string) (articles []*Article, err error) {
NewsItem []*Article `json:"news_item"`
}
err = util.DecodeWithError(response, &res, "GetDraft")
if err != nil {
return
}

articles = res.NewsItem
return
return res.NewsItem, err
}

// DeleteDraft 删除草稿
Expand Down Expand Up @@ -172,12 +163,7 @@ func (draft *Draft) CountDraft() (total uint, err error) {
Total uint `json:"total_count"`
}
err = util.DecodeWithError(response, &res, "CountDraft")
if nil != err {
return
}

total = res.Total
return
return res.Total, err
}

// ArticleList 草稿列表
Expand Down
14 changes: 2 additions & 12 deletions officialaccount/freepublish/freepublish.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ func (freePublish *FreePublish) Publish(mediaID string) (publishID int64, err er
PublishID int64 `json:"publish_id"`
}
err = util.DecodeWithError(response, &res, "SubmitFreePublish")
if err != nil {
return
}

publishID = res.PublishID
return
return res.PublishID, err
}

// PublishStatusList 发布任务状态列表
Expand Down Expand Up @@ -191,12 +186,7 @@ func (freePublish *FreePublish) First(articleID string) (list []Article, err err
NewsItem []Article `json:"news_item"`
}
err = util.DecodeWithError(response, &res, "FirstFreePublish")
if err != nil {
return
}

list = res.NewsItem
return
return res.NewsItem, err
}

// ArticleList 发布列表
Expand Down
31 changes: 5 additions & 26 deletions officialaccount/message/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ func (tpl *Subscribe) List() (templateList []*PrivateSubscribeItem, err error) {
}
var res resPrivateSubscribeList
err = util.DecodeWithError(response, &res, "ListSubscribe")
if err != nil {
return
}
templateList = res.SubscriptionList
return
return res.SubscriptionList, err
}

type resSubscribeAdd struct {
Expand Down Expand Up @@ -123,11 +119,7 @@ func (tpl *Subscribe) Add(ShortID string, kidList []int, sceneDesc string) (temp
}
var result resSubscribeAdd
err = util.DecodeWithError(response, &result, "AddSubscribe")
if err != nil {
return
}
templateID = result.TemplateID
return
return result.TemplateID, err
}

// Delete 删除私有模板
Expand Down Expand Up @@ -175,11 +167,7 @@ func (tpl *Subscribe) GetCategory() (categoryList []*PublicTemplateCategory, err
}
var result resSubscribeCategoryList
err = util.DecodeWithError(response, &result, "GetCategory")
if err != nil {
return
}
categoryList = result.CategoryList
return
return result.CategoryList, err
}

// PublicTemplateKeyWords 模板中的关键词
Expand Down Expand Up @@ -210,11 +198,7 @@ func (tpl *Subscribe) GetPubTplKeyWordsByID(titleID string) (keyWordsList []*Pub
}
var result resPublicTemplateKeyWordsList
err = util.DecodeWithError(response, &result, "GetPublicTemplateKeyWords")
if err != nil {
return
}
keyWordsList = result.KeyWordsList
return
return result.KeyWordsList, err
}

// PublicTemplateTitle 类目下的公共模板
Expand Down Expand Up @@ -246,10 +230,5 @@ func (tpl *Subscribe) GetPublicTemplateTitleList(ids string, start int, limit in
}
var result resPublicTemplateTitleList
err = util.DecodeWithError(response, &result, "GetPublicTemplateTitle")
if err != nil {
return
}
count = result.Count
templateTitleList = result.TemplateTitleList
return
return result.Count, result.TemplateTitleList, err
houseme marked this conversation as resolved.
Show resolved Hide resolved
}
12 changes: 2 additions & 10 deletions officialaccount/message/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ func (tpl *Template) List() (templateList []*TemplateItem, err error) {
}
var res resTemplateList
err = util.DecodeWithError(response, &res, "ListTemplate")
if err != nil {
return
}
templateList = res.TemplateList
return
return res.TemplateList, err
houseme marked this conversation as resolved.
Show resolved Hide resolved
}

type resTemplateAdd struct {
Expand Down Expand Up @@ -143,11 +139,7 @@ func (tpl *Template) Add(shortID string) (templateID string, err error) {

var result resTemplateAdd
err = util.DecodeWithError(response, &result, "AddTemplate")
if err != nil {
return
}
templateID = result.TemplateID
return
return result.TemplateID, err
}
houseme marked this conversation as resolved.
Show resolved Hide resolved

// Delete 删除私有模板.
Expand Down
4 changes: 0 additions & 4 deletions officialaccount/user/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ func (user *User) ListChangeOpenIDs(fromAppID string, openIDs ...string) (list *
}

err = util.DecodeWithError(resp, list, "ListChangeOpenIDs")
if err != nil {
return
}

return
}

Expand Down
8 changes: 1 addition & 7 deletions officialaccount/user/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ func (user *User) GetTag() (tags []*TagInfo, err error) {
Tags []*TagInfo `json:"tags"`
}
err = json.Unmarshal(response, &result)
if err != nil {
return
}
return result.Tags, nil
return result.Tags, err
houseme marked this conversation as resolved.
Show resolved Hide resolved
}

// OpenIDListByTag 获取标签下粉丝列表
Expand All @@ -154,9 +151,6 @@ func (user *User) OpenIDListByTag(tagID int32, nextOpenID ...string) (userList *
}
userList = new(TagOpenIDList)
err = json.Unmarshal(response, &userList)
if err != nil {
return
}
return
}

Expand Down
Loading
Loading