github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/apiserver/testing/errors.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package testing
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/juju/juju/rpc/params"
    10  )
    11  
    12  var ErrUnauthorized = &params.Error{
    13  	Message: "permission denied",
    14  	Code:    params.CodeUnauthorized,
    15  }
    16  
    17  func NotFoundError(prefixMessage string) *params.Error {
    18  	return &params.Error{
    19  		Message: fmt.Sprintf("%s not found", prefixMessage),
    20  		Code:    params.CodeNotFound,
    21  	}
    22  }
    23  
    24  func NotSupportedError(prefixMessage string) *params.Error {
    25  	return &params.Error{
    26  		Message: fmt.Sprintf("%s not supported", prefixMessage),
    27  		Code:    params.CodeNotSupported,
    28  	}
    29  }
    30  
    31  func NotProvisionedError(machineId string) *params.Error {
    32  	return &params.Error{
    33  		Message: fmt.Sprintf("machine %s not provisioned", machineId),
    34  		Code:    params.CodeNotProvisioned,
    35  	}
    36  }
    37  
    38  func NotAssignedError(unitName string) *params.Error {
    39  	return &params.Error{
    40  		Message: fmt.Sprintf("unit %q is not assigned to a machine", unitName),
    41  		Code:    params.CodeNotAssigned,
    42  	}
    43  }
    44  
    45  func AlreadyExistsError(what string) *params.Error {
    46  	return &params.Error{
    47  		Message: fmt.Sprintf("%s already exists", what),
    48  		Code:    params.CodeAlreadyExists,
    49  	}
    50  }
    51  
    52  func ServerError(message string) *params.Error {
    53  	return &params.Error{
    54  		Message: message,
    55  		Code:    "",
    56  	}
    57  }
    58  
    59  func PrefixedError(prefix, message string) *params.Error {
    60  	return ServerError(prefix + message)
    61  }