github.com/blend/go-sdk@v1.20220411.3/ex/err_class.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package ex
     9  
    10  // ErrClass returns the exception class or the error message.
    11  // This depends on if the err is itself an exception or not.
    12  func ErrClass(err interface{}) error {
    13  	if err == nil {
    14  		return nil
    15  	}
    16  	if ex := As(err); ex != nil && ex.Class != nil {
    17  		return ex.Class
    18  	}
    19  	if typed, ok := err.(ClassProvider); ok && typed != nil {
    20  		return typed.Class()
    21  	}
    22  	if typed, ok := err.(error); ok && typed != nil {
    23  		return typed
    24  	}
    25  	return nil
    26  }