Improve error message #218
-
Hello! Instead of giving a
Code:
I am using the SDK |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Hi @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)
}
} |
Beta Was this translation helpful? Give feedback.
-
hi @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! |
Beta Was this translation helpful? Give feedback.
Hi @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