github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/state/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/state/api/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 NotProvisionedError(machineId string) *params.Error {
    25  	return &params.Error{
    26  		Message: fmt.Sprintf("machine %s is not provisioned", machineId),
    27  		Code:    params.CodeNotProvisioned,
    28  	}
    29  }
    30  
    31  func NotAssignedError(unitName string) *params.Error {
    32  	return &params.Error{
    33  		Message: fmt.Sprintf("unit %q is not assigned to a machine", unitName),
    34  		Code:    params.CodeNotAssigned,
    35  	}
    36  }
    37  
    38  func AlreadyExistsError(what string) *params.Error {
    39  	return &params.Error{
    40  		Message: fmt.Sprintf("%s already exists", what),
    41  		Code:    params.CodeAlreadyExists,
    42  	}
    43  }
    44  
    45  func ServerError(message string) *params.Error {
    46  	return &params.Error{
    47  		Message: message,
    48  		Code:    "",
    49  	}
    50  }
    51  
    52  func PrefixedError(prefix, message string) *params.Error {
    53  	return ServerError(prefix + message)
    54  }