Skip to content

Commit

Permalink
feature: v0.4.1 throw custom error on Template exception
Browse files Browse the repository at this point in the history
  • Loading branch information
tschuehly committed Mar 27, 2023
1 parent a01e076 commit 2805ad8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.tschuehly.thymeleafviewcomponent

class ViewComponentProcessingException(message: String?, cause: Throwable?) : Exception(message, cause) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException
import org.thymeleaf.context.ITemplateContext
import org.thymeleaf.context.WebEngineContext
import org.thymeleaf.engine.AttributeName
import org.thymeleaf.exceptions.TemplateProcessingException
import org.thymeleaf.model.IProcessableElementTag
import org.thymeleaf.processor.element.AbstractAttributeTagProcessor
import org.thymeleaf.processor.element.IElementTagStructureHandler
Expand Down Expand Up @@ -54,9 +55,13 @@ class ViewComponentProcessor(dialectPrefix: String) :
} catch (e: NoSuchBeanDefinitionException) {
throw ViewComponentBeanNotFoundException("No ViewComponentBean with the name: \"$componentName\" found")
}
val expression = parser.parseExpression(webContext, expressionString)

val viewContext = expression.execute(webContext) as ViewContext
val expression = parser.parseExpression(webContext, expressionString)
val viewContext = try {
expression.execute(webContext) as ViewContext
} catch (e: TemplateProcessingException) {
throw ViewComponentProcessingException(e.message, e.cause)
}
val engine = appCtx.getBean(SpringTemplateEngine::class.java)

webContext.setVariables(viewContext.contextAttributes.toMap())
Expand Down

0 comments on commit 2805ad8

Please sign in to comment.