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

エラーハンドリングの改善 #33

Merged
merged 2 commits into from
Mar 23, 2022

Conversation

yamamoto-febc
Copy link
Member

@yamamoto-febc yamamoto-febc commented Mar 23, 2022

closes #32

  • エラーレスポンス後に再度レスポンスを書いてしまう問題を修正
  • ErrorNNN型でerrorインターフェースを実装

ErrorNNN型はErrorというフィールドを持つためにerrorインターフェースを実装できなかったが、oapi-codegenのx-oapi-codegen-extra-tagsエクステンションを用いてフィールドの名前を変えつつJSONタグは維持することでこの問題を解消しerrorインターフェースを実装した。

これにより、クライアント側で以下のような判定が行えるようになる。

	account, err := client.Read(ctx, req.SiteId)
	if err != nil {
		if _, ok := err.(*v1.Error404); ok {
			// 404エラー時の処理をここで実装
		}
		return nil, err
	}

ErrorNNN型はErrorというフィールドを持つためにerrorインターフェースを実装できなかったが、
oapi-codegenのx-oapi-codegen-extra-tagsエクステンションを用いて
フィールドの名前を変えつつJSONタグは維持することでこの問題を解消しerrorインターフェースを実装した。
@yamamoto-febc yamamoto-febc merged commit 89c78dc into sacloud:main Mar 23, 2022
@yamamoto-febc yamamoto-febc deleted the fix/error-handling branch March 23, 2022 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

クライアント側でエラー型情報が受け取れない
1 participant