/* Copyright © 2026 Thomas von Dein This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package es import ( "errors" "fmt" "strings" "github.com/elastic/go-elasticsearch/v9/typedapi/types" ) func esErrorString(err error) error { msg := err.Error() //nolint:gocritic switch errVal := err.(type) { case *types.ElasticsearchError: var causes strings.Builder for _, cause := range errVal.ErrorCause.RootCause { fmt.Fprintf(&causes, "%s\n", *cause.Reason) } if errVal.ErrorCause.Reason != nil { msg = *errVal.ErrorCause.Reason + ": " + causes.String() } else { msg = fmt.Sprintf("http status %d: ", errVal.Status) } } return errors.New(msg) }