mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-10 09:10:27 -04:00
* Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl. * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
39 lines
965 B
Go
39 lines
965 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
)
|
|
|
|
const (
|
|
_ = iota
|
|
InvalidClientConfig
|
|
)
|
|
|
|
// ClientError represents a generic error for the Cloud Packer Service client.
|
|
type ClientError struct {
|
|
StatusCode uint
|
|
Err error
|
|
}
|
|
|
|
// Error returns the string message for some ClientError.
|
|
func (c *ClientError) Error() string {
|
|
return fmt.Sprintf("status %d: err %v", c.StatusCode, c.Err)
|
|
}
|
|
|
|
// CheckErrorCode checks the error string for err for some code and returns true
|
|
// if the code is found. Ideally this function should use status.FromError
|
|
// https://pkg.go.dev/google.golang.org/grpc/status#pkg-functions but that
|
|
// doesn't appear to work for all of the Cloud Packer Service response errors.
|
|
func CheckErrorCode(err error, code codes.Code) bool {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
|
|
return strings.Contains(err.Error(), fmt.Sprintf("Code:%d", code))
|
|
}
|