Custom plugin: return logical.ErrorResponse and/or error?


I’m currently writing a custom vault plugin. I wonder why the Callback of framework.PathOperation has two return values.
I mean this type:
type OperationFunc func(context.Context, *logical.Request, *FieldData) (*logical.Response, error)

If my callback encounteres an error, i can return logical.ErrorResponse to inform the user, that something went horribly wrong. What is the use of the error return type in this context? What is it used for?

Can anyone tell me if there are best practices when to set which return value?

If you read some general introductions to Go programming, you will find that the error type is a standard convention in the Go language.

Returning a logical.ErrorResponse => successfully composing an appropriate HTTP error response to return to the Vault client.

Returning an error => reporting a program malfunction, similar to throwing an exception in other languages.