mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
added basic error handling around templates rendering
This commit is contained in:
parent
27a97b7fa8
commit
53fa15d3db
2 changed files with 23 additions and 6 deletions
|
@ -7,13 +7,19 @@ module.exports = TemplatesWebController =
|
|||
renderTemplatesIndexPage: (req, res)->
|
||||
logger.log "rendering index page of templates"
|
||||
TemplatesWebController._getDataFromTemplatesApi "/user/#{req.params.user_id}", (err, data)->
|
||||
if err?
|
||||
logger.err err:err, "something went wrong in renderTemplatesIndexPage"
|
||||
return res.send 500
|
||||
data.title = "LaTeX Templates"
|
||||
res.render "templates/index", data
|
||||
|
||||
renerTemplateInTag: (req, res)->
|
||||
logger.log "rendering latex template page"
|
||||
{user_id, tag_name, template_name} = req.params
|
||||
logger.log user_id:user_id, tag_name:tag_name, template_name:template_name, "rendering latex template page"
|
||||
TemplatesWebController._getDataFromTemplatesApi "/user/#{user_id}/tag/#{tag_name}/template/#{template_name}", (err, data)->
|
||||
if err?
|
||||
logger.err err:err, user_id:user_id, tag_name:tag_name, template_name:template_name, "something went wrong in renerTemplateInTag"
|
||||
return res.send 500
|
||||
data.title = data.template.name
|
||||
res.render "templates/template", data
|
||||
|
||||
|
@ -37,28 +43,37 @@ module.exports = TemplatesWebController =
|
|||
logger.error err: error, "templates proxy API error"
|
||||
res.send 500
|
||||
|
||||
_renderCanonicalPage: _renderCanonicalPage = (req, res)->
|
||||
_renderCanonicalPage: (req, res)->
|
||||
{user_id, template_id} = req.params
|
||||
logger.log user_id:user_id, template_id:template_id, "rendering template page"
|
||||
TemplatesWebController._getDataFromTemplatesApi "/user/#{user_id}/template/#{template_id}", (err, data)->
|
||||
if err?
|
||||
logger.err err:err, user_id:user_id, template_id:template_id, "something went wrong in _renderCanonicalPage"
|
||||
return res.send 500
|
||||
data.tag = null
|
||||
res.render "templates/template", data
|
||||
|
||||
_renderAllTemplatesPage: _renderAllTemplatesPage = (req, res)->
|
||||
_renderAllTemplatesPage: (req, res)->
|
||||
{user_id} = req.params
|
||||
logger.log user_id:user_id, "rendering all templates page"
|
||||
TemplatesWebController._getDataFromTemplatesApi "/user/#{user_id}/all", (err, data)->
|
||||
if err?
|
||||
logger.err err:err, user_id:user_id, "something went wrong in _renderCanonicalPage"
|
||||
return res.send 500
|
||||
data.title = "All Templates"
|
||||
res.render "templates/tag", data
|
||||
|
||||
_renderTagPage: _renderTagPage = (req, res)->
|
||||
_renderTagPage: (req, res)->
|
||||
{user_id, tag_name} = req.params
|
||||
logger.log user_id:user_id, tag_name:tag_name, "rendinging tag page for templates"
|
||||
TemplatesWebController._getDataFromTemplatesApi "/user/#{user_id}/tag/#{tag_name}", (err, data)->
|
||||
if err?
|
||||
logger.err err:err, user_id:user_id, tag_name:tag_name, "something went wrong in _renderCanonicalPage"
|
||||
return res.send 500
|
||||
data.title = data.tag.name
|
||||
res.render "templates/tag", data
|
||||
|
||||
_getDataFromTemplatesApi: _getDataFromTemplatesApi = (path, callback)->
|
||||
_getDataFromTemplatesApi: (path, callback)->
|
||||
opts =
|
||||
url: "#{settings.apis.templates_api.url}#{path}"
|
||||
json:true
|
||||
|
|
|
@ -16,7 +16,9 @@ describe "TemplatesWebController", ->
|
|||
url:"templates.sharelatex.env"
|
||||
@TemplatesWebController = SandboxedModule.require modulePath, requires:
|
||||
"settings-sharelatex":@settings
|
||||
"logger-sharelatex": log:->
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
err:->
|
||||
@stubbedApiData =
|
||||
template:{_id:"12312321", name:"bob"}
|
||||
tag: {name:"tag name"}
|
||||
|
|
Loading…
Reference in a new issue