github.com/blend/go-sdk@v1.20240719.1/ex/as.go (about) 1 /* 2 3 Copyright (c) 2024 - 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 import ( 11 "errors" 12 ) 13 14 // As is a helper method that returns an error as an ex. 15 // 16 // Deprecated: Use [errors.As] with [*Ex]. Make sure `As()` and `Unwrap()` are 17 // properly implemented on your custom classes. 18 func As(err interface{}) *Ex { 19 switch typed := err.(type) { 20 case error: 21 var exx *Ex 22 if errors.As(typed, &exx) { 23 return exx 24 } 25 return nil 26 case Ex: 27 return &typed 28 default: 29 return nil 30 } 31 }