In generall, iam-go errors can be divided into two types:
- IAM Server Errors: returned by the IAM API Server itself
- IAM Client Errors: returned by the iam-go library
Any of these can be handled as a special type: iamerrors.Error.
Below are some examples on how to handle these errors:
- You can use errors.Is to identify the type of error:
if err != nil {
switch {
case errors.Is(err, iamerrors.ErrForbidden):
log.Fatalf("No rights: %s", err.Error())
}
...
}- You can cast a returned error to iamerrors.Error with errors.As and get the specific info (description of an error, for example):
if err != nil {
var iamError *iamerrors.Error
if errors.As(err, &iamError) {
log.Fatalf("IAM Error! Description: %s", iamError.Desc)
}
...
}