 
 updateUser = (req, resp) ->
   User.findByShortName req.user.real.shortName, (err, user) ->
+    if err?
+      resp.send 500, error: err
+      return
+
     console.log "updateUser body is", req.body
     # The attributes that we can set via this API.
     canSet = ['acceptedTerms', 'canBeReally', 'datasetDisplay']

      plan = result.subscription.plan
      console.log 'Subscribed to', plan.plan_code
      user.setAccountLevel plan.plan_code, (err) ->
        if req.user?.effective
          req.user.effective = getSessionUser user
        req.session.save()

    _.extend options, pageTitles.PageTitles[options.page]
    options.subnav ?= 'subnav'
    fs.readFile "client/template/#{options.subnav}.eco", (err, subnavTemplate) ->
      if err?
        console.warn "Template #{options.page} not found when rendering server side"
        return resp.send 500, {error: "Template not found: #{err}"}

      fs.readFile "client/template/nav.eco", (err, navTemplate) ->
        if err?
          console.warn "Template #{options.page} not found when rendering server side"
          return resp.send 500, {error: "Template not found: #{err}"}

        getSessionUsersFromDB req.user, (usersObj) ->
          resp.render 'index',
              title: options.title or 'ScraperWiki'
