func MyAPIRequest(params SomeParams) (interface{}, error) { if err := validate(params); err != nil { return nil, ¶ms.ErrorResults{[]string{err.Error()}} } // API request logic }
func AnotherAPIRequest() (interface{}, error) { results := ¶ms.ErrorResults{} // API request logic if err1 != nil { results.AddError(err1) } if err2 != nil { results.AddError(err2) } if err3 != nil { results.AddError(err3) } if results.Any() { return nil, results } // Return non-error response }Here, `AnotherAPIRequest` uses `ErrorResults` to accumulate and return multiple errors if they occur during the API request. The `AddError` method is used to append errors to the `results` slice, and the `Any` method checks if any errors were added. Overall, `ErrorResults` is a valuable tool in the `github.com/juju/juju/apiserver/params` package library for handling API request errors in a structured and efficient manner.