Skip to content

Commit

Permalink
Update examples to simplify error usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jasdel committed Aug 19, 2015
1 parent af3707f commit e8f760d
Show file tree
Hide file tree
Showing 53 changed files with 7,221 additions and 18,877 deletions.
4 changes: 1 addition & 3 deletions internal/model/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,12 @@ func (a *API) ExampleGoCode() string {
exs = append(exs, o.Example())
}

code := fmt.Sprintf("import (\n%q\n%q\n%q\n\n%q\n%q\n%q\n%q\n)\n\n"+
code := fmt.Sprintf("import (\n%q\n%q\n%q\n\n%q\n%q\n)\n\n"+
"var _ time.Duration\nvar _ bytes.Buffer\n\n%s",
"bytes",
"fmt",
"time",
"github.com/aws/aws-sdk-go/aws",
"github.com/aws/aws-sdk-go/aws/awserr",
"github.com/aws/aws-sdk-go/aws/awsutil",
"github.com/aws/aws-sdk-go/service/"+a.PackageName(),
strings.Join(exs, "\n\n"),
)
Expand Down
18 changes: 5 additions & 13 deletions internal/model/api/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,14 @@ func Example{{ .API.StructName }}_{{ .ExportedName }}() {
resp, err := svc.{{ .ExportedName }}(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// Generic AWS error with Code, Message, and original error (if any)
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
if reqErr, ok := err.(awserr.RequestFailure); ok {
// A service error occurred
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
}
} else {
// This case should never be hit, the SDK should always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(awsutil.Prettify(resp))
fmt.Println(resp)
}
`))

Expand Down
Loading

0 comments on commit e8f760d

Please sign in to comment.