Permalink
Browse files

Closes #918. Use LiftRules.devModeFailureResponseCodeOverride to chan…

…ge the devMode and testMode HTTP response code on snippet failure
  • Loading branch information...
1 parent e258f20 commit b98cfdc315feddff91ae8e02ba2a26970308ba4d @dpp dpp committed Mar 16, 2011
@@ -985,6 +985,14 @@ trait LiftRules extends Factory with FormVendor with LazyLoggable {
*/
@volatile var throwOnOutOfScopeVarAccess: Boolean = false
+ /**
+ * In Dev mode and Test mode, return a non-200 response code
+ * if there is an error on the page (one that would result in
+ * the red box with the error message being displayed). This
+ * helps in automate testing
+ */
+ @volatile var devModeFailureResponseCodeOverride: Box[Int] = Empty
+
/**
* Returns the HTTPContext
*/
@@ -979,31 +979,35 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
* @returns a Box of LiftResponse with all the proper page rewriting
*/
def processTemplate(template: Box[NodeSeq], request: Req, path: ParsePath, code: Int): Box[LiftResponse] = {
- (template or findVisibleTemplate(path, request)).map {
- xhtmlBase =>
- fullPageLoad.doWith(true) { // allow parallel snippets
- val xhtml = LiftSession.checkForContentId(xhtmlBase)
- // Phase 1: snippets & templates processing
- val rawXml: NodeSeq = processSurroundAndInclude(PageName get, xhtml)
-
- // Make sure that functions have the right owner. It is important for this to
- // happen before the merge phase so that in merge to have a correct view of
- // mapped functions and their owners.
- updateFunctionMap(S.functionMap, RenderVersion get, millis)
-
- // Phase 2: Head & Tail merge, add additional elements to body & head
- val xml = merge(rawXml, request)
-
- notices = Nil
- // Phase 3: Response conversion including fixHtml
- LiftRules.convertResponse((xml, code),
- S.getHeaders(LiftRules.defaultHeaders((xml, request))),
- S.responseCookies,
- request)
- }
+ overrideResponseCode.doWith(Empty) {
+ (template or findVisibleTemplate(path, request)).map {
+ xhtmlBase =>
+ fullPageLoad.doWith(true) { // allow parallel snippets
+ val xhtml = LiftSession.checkForContentId(xhtmlBase)
+ // Phase 1: snippets & templates processing
+ val rawXml: NodeSeq = processSurroundAndInclude(PageName get, xhtml)
+
+ // Make sure that functions have the right owner. It is important for this to
+ // happen before the merge phase so that in merge to have a correct view of
+ // mapped functions and their owners.
+ updateFunctionMap(S.functionMap, RenderVersion get, millis)
+
+ // Phase 2: Head & Tail merge, add additional elements to body & head
+ val xml = merge(rawXml, request)
+
+ notices = Nil
+ // Phase 3: Response conversion including fixHtml
+ LiftRules.convertResponse((xml, overrideResponseCode.is openOr code),
+ S.getHeaders(LiftRules.defaultHeaders((xml, request))),
+ S.responseCookies,
+ request)
+ }
+ }
}
}
+ private object overrideResponseCode extends TransientRequestVar[Box[Int]](Empty)
+
/**
* If the sitemap entry for this Req is marked stateless,
* run the rest of the request as stateless
@@ -1341,8 +1345,13 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
{
for{
f <- LiftRules.snippetFailedFunc.toList
- }
+ } {
f(LiftRules.SnippetFailure(page, snippetName, why))
+ }
+
+ if (Props.devMode || Props.testMode) {
+ overrideResponseCode.set(LiftRules.devModeFailureResponseCodeOverride)
+ }
Helpers.errorDiv(
<div>Error processing snippet: <b>{snippetName openOr "N/A"}</b><br/>

0 comments on commit b98cfdc

Please sign in to comment.