Files
plex-sdk-docs/content/pages/01-reference/go/errors/_snippet.mdx

46 lines
956 B
Plaintext

{/* Start Go Errors */}
Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both. When specified by the OpenAPI spec document, the SDK will return the appropriate subclass.
### Example
```go
package main
import (
"context"
"errors"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/components"
"github.com/LukeHagar/plexgo/models/sdkerrors"
"log"
)
func main() {
s := plexgo.New(
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
plexgo.WithXPlexClientIdentifier("<value>"),
)
ctx := context.Background()
res, err := s.Server.GetServerCapabilities(ctx)
if err != nil {
var e *sdkerrors.GetServerCapabilitiesResponseBody
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
var e *sdkerrors.SDKError
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
}
}
```
{/* End Go Errors */}