Skip to content

Latest commit

 

History

History
34 lines (26 loc) · 878 Bytes

File metadata and controls

34 lines (26 loc) · 878 Bytes

Error Handling

In generall, iam-go errors can be divided into two types:

  1. IAM Server Errors: returned by the IAM API Server itself
  2. 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:

  1. 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())
    }
    ...
}
  1. 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)
    }
    ...
}