开发者

how to display grails error from bootstrap

开发者 https://www.devze.com 2023-01-12 13:56 出处:网络
I just found annoying bug from my bootstrap.groovy. If I did a mistake for example, like undeclared variable, the apps keep running and then when I tried to access the apps from web it will display

I just found annoying bug from my bootstrap.groovy. If I did a mistake for example, like undeclared variable, the apps keep running and then when I tried to access the apps from web it will display

HTTP Status 404 -

type Status report

message

description The requested resource () is not available. Apache Tomcat/6.0-snapshot

in the console there is no error messages appear ... so it makes confuse. suppose I edit 10 bootstrap and in one of them I did make a mistakes, it would become so difficult to fi开发者_JAVA百科nd that little bug.

any idea how to solve this problem ? is it a tips to display those errors ?


I don't know what you're doing in your bootstrap, but if its failing when you're saving domain objects, then you can log those as errors the same way you would in a controller. If you want the errors to go to a console, just set up a console appender:

//Remember, save calls validate()
if(!myObject.save()) {
    myObject.errors.allErrors.each {
        log.error it
    }
}

References:

  • Logging in grails
  • Validating constraints


For other time use you can use this show error method not only on domain object like myObject.save() but also any method having an exception or a service like this one :

def searchService 

searchService.search(person)  // inside hibernate create criteria or any db actitvity or ...

seachService.errors.allErrors,each {
flash.message = message(code:'default.search.error.message',default : it) //see it in freindly view
 //Or println("${new Date()}"it)
}



you need a lable flash message on your in case of other files than bootstrap 

<g:set var="entityName" value="${message(code: 'domainClassName.label', default: 'what ever')}" />
        <title><g:message code="default.list.label" args="[entityName]" /></title>


    <h1><g:message code="default.list.label" args="[entityName]" /></h1>
            <g:if test="${flash.message}">
            <div class="message" role="status">${flash.message}</div>
            </g:if>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号