Skip to content

Commit

Permalink
Change wrapException behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Idane committed Aug 15, 2021
1 parent 336aa86 commit 3f76404
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.aspectj.lang.annotation.Aspect
import org.aspectj.lang.annotation.Pointcut
import org.aspectj.lang.reflect.MethodSignature
import org.springframework.core.annotation.AnnotationUtils
import kotlin.reflect.full.createInstance
import kotlin.reflect.full.primaryConstructor

@Aspect
class WrapExceptionAspect {
Expand Down Expand Up @@ -37,7 +37,17 @@ class WrapExceptionAspect {
throw e
}

val exceptionInstance = actualAnnotation.value.createInstance().initCause(e)
val exceptionInstance = if(e.message == null) {
val message = if(e is NullPointerException) {
"Null pointer"
} else {
"No message"
}
exceptionClazz.primaryConstructor?.call(message)?.initCause(e)

} else {
exceptionClazz.primaryConstructor?.call(e.message)?.initCause(e)
} ?: e
throw exceptionInstance
}
}
Expand Down

0 comments on commit 3f76404

Please sign in to comment.