Skip to content
Myr

wrap try/catch around render()

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent a75e60a · Browse files · 1 file+41 added−36 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+41 added−36 removed

  • other:+41 added−36 removed

1 file+41 added−36 removed

modified:lib/view.js+41 added-36 removed
212 unmodified lines
213 if ('function' == typeof opts) {214 fn = opts, opts = null;215 }216217 try {218 return this._render(view, opts, fn, parent, sub);219 } catch (err) {220 // callback given221 if (fn) {222 fn(err);223 // unwind to root call224 } else if (sub) {225 throw err;226 // root template, next(err)227 } else {228 this.req.next(err);229 }230 }231};232233// private render()234235res._render = function(view, opts, fn, parent, sub){236 var options = {}237 , self = this238 , app = this.app239 , helpers = app.viewHelpers
92 unmodified lines
332 // Provide filename to engine333 options.filename = view.path;334335 // Attempt render317 try {318 var engine = view.templateEngine319 , template = cacheTemplates320 ? cache[view.path] || (cache[view.path] = engine.compile(view.contents, options))321 : engine.compile(view.contents, options)322 , str = template.call(options.scope, options);336 var engine = view.templateEngine337 , template = cacheTemplates338 ? cache[view.path] || (cache[view.path] = engine.compile(view.contents, options))339 : engine.compile(view.contents, options)340 , str = template.call(options.scope, options);341324 // layout expected325 if (layout) {326 options.isLayout = true;327 options.layout = false;328 options.body = str;329 this.render(layout, options, fn, view, true);330 // partial return331 } else if (partial) {332 return str;333 // render complete, and 334 // callback given335 } else if (fn) {336 fn(null, str);337 // respond338 } else {339 this.send(str);340 }341342 } catch (err) {343 // callback given344 if (fn) {345 fn(err);346 // unwind to root call347 } else if (sub) {348 throw err;349 // root template, next(err)350 } else {351 this.req.next(err);352 }342 // layout expected343 if (layout) {344 options.isLayout = true;345 options.layout = false;346 options.body = str;347 this.render(layout, options, fn, view, true);348 // partial return349 } else if (partial) {350 return str;351 // render complete, and 352 // callback given353 } else if (fn) {354 fn(null, str);355 // respond356 } else {357 this.send(str);358 }354};359}360361/**362 * Hint at view path resolution, outputting the363 * paths that Express has tried.
14 unmodified lines