Skip to content

How to Satisfy the smithy.APIError Interface in Go #2858

Answered by lucix-aws
erikpaasonen asked this question in Q&A
Discussion options

You must be logged in to vote

V2 test code returning a custom struct which ought to satisfy Smithy-Go, but unfortunately not working:

type mockApiError struct {
    ErrorCode string
    ErrorMsg  string
    Fault     smithy.ErrorFault
}

This doesn't actually satisfy smithy.APIError though - you don't have the corresponding methods on that struct, unless your sample just doesn't show them (don't see how it could, though - you have an ErrorCode field, so you can't have an ErrorCode() method too)

Double-check that you're satisfying the interface w/

var _ smithy.APIError = (*mockApiError)(nil)

You want something like

type mockError struct {
  code, msg string
  fault smithy.ErrorFault
}

func(m *mockError) ErrorCode() s…

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by erikpaasonen
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@erikpaasonen
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2857 on October 29, 2024 18:23.