Error Handling #
All methods return an "error" struct, which holds a non-nil value if the call failed. Error structs are all of type KuzzleError
.
The KuzzleError
type implements the standard error
interface, and adds the following properties to it:
Property | Type | Description |
---|---|---|
Status | int | Status following HTTP Standards |
Stack | string | Error stacktrace (Only in development mode) |
You can find a detailed list of possible errors messages and statuses in the documentation API.
Example #
err := kuzzle.Index.Create("nyc-open-data", nil)
if err != nil {
fmt.Println(err.Error())
// Type assertion of error to KuzzleError
if err.(types.KuzzleError).Status == 400 {
fmt.Println("Try with another name!")
}
}
Edit this page on Github(opens new window)