func NewUnverifiedError() *Error {
	return &Error{
		Type: UnauthorizedError,
		Err: []string{"Your account has not yet been verified.\n\n" +
			"Please check your email for your verification code and follow the enclosed instructions.\n" +
			"Once you have verified your account you may retry this operation."},
	}
}
NewUnverifiedError returns a message telling the user to verify their account before continuing
package apitypes
import (
	"encoding/json"
	"strings"
	"github.com/manifoldco/go-base64"
	"github.com/manifoldco/torus-cli/envelope"
	"github.com/manifoldco/torus-cli/identity"
)
type ErrorType string
const (
	BadRequestError     = "bad_request"
	UnauthorizedError   = "unauthorized"
	NotFoundError       = "not_found"
	RequestTimeoutError = "request_timeout"
	InternalServerError = "internal_server"
	NotImplementedError = "not_implemented"
	UnknownError        = "unknown_error"
)
var errorTypeToStatusCodeMap = map[ErrorType]int{
	BadRequestError:     400,
	UnauthorizedError:   401,
	NotFoundError:       404,
	RequestTimeoutError: 408,
	InternalServerError: 500,
	NotImplementedError: 501,
	UnknownError:        0,
}
func LookupErrorType(code int) ErrorType {
	for t, c := range errorTypeToStatusCodeMap {
		if c == code {
			return t
		}
	}
	return UnknownError
}
type Error struct {
	Type ErrorType `json:"type"`
	Err  []string  `json:"error"`
}
func (e *Error) Error() string {
	segments := strings.Split(string(e.Type), "_")
	errType := strings.Join(segments, " ")
	return strings.Title(errType) + ": " + strings.Join(e.Err, " ")
}
func (e *Error) StatusCode() int {
	code, ok := errorTypeToStatusCodeMap[e.Type]
	if !ok || code == 0 {
		return 500
	}
	return code
}
func FormatError(err error) error {
	if err == nil {
		return nil
	}
	if apiErr, ok := err.(*Error); ok {
		if apiErr.Type == UnauthorizedError {
			for _, m := range apiErr.Err {
				if strings.Contains(m, "wrong identity state: unverified") {
					return NewUnverifiedError()
				}
			}
			return &Error{
				Type: UnauthorizedError,
				Err:  []string{"You are unauthorized to perform this action."},
			}
		}
	}
	return err
}