Improve error message #218
Answered
by
baywet
Subhajit Mondal (Subhajit97)
asked this question in
Q&A
|
Hello! Instead of giving a Code: I am using the SDK |
Answered by
baywet
Jul 15, 2022
Replies: 2 comments 7 replies
|
Hi Subhajit Mondal (@Subhajit97) import (
"github.com/microsoftgraph/msgraph-sdk-go/models/odataerrors"
)
result, err := client.Me().Drive().Get()
if err != nil {
fmt.Printf("Error getting the drive: %v\n", err)
printOdataError(err)
}
fmt.Printf("Found Drive : %v\n", *result.GetId())
// omitted for brevity
func printOdataError(err error) {
switch err.(type) {
case *odataerrors.ODataError:
typed := err.(*odataerrors.ODataError)
fmt.Printf("error:", typed.Error())
if terr := typed.GetError(); terr != nil {
fmt.Printf("code: %s", *terr.GetCode())
fmt.Printf("msg: %s", *terr.GetMessage())
}
default:
fmt.Printf("%T > error: %#v", err, err)
}
} |
1 reply
Answer selected by
Subhajit97
|
hi Vincent Biret (@baywet), i had a followup question: is matching against the string message the best way to check for specific error types? i.e. if err := typed.GetError(); err != nil &&
*err.GetCode() == "Request_BadRequest" &&
strings.Contains(*err.GetMessage(), "One or more added object references already exist for the following modified properties") {
// ... do something
}I didn't see a more stable looking error code available in the returned type.. thanks! |
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Subhajit Mondal (@Subhajit97)
Thanks for using the Go SDK and for reaching out.
We've just had a community contribution yesterday that documents how to getter better information from the errors are you can see here