     initializeDSView ->
         if productionOrTest
             # Recover all applications in database
-            recoverApp (err, apps) =>
+            recoverApp (err, apps) ->
                 return callback err if err?
                 # Recover all design docs in database
-                recoverDesignDocs (err, docs) =>
+                recoverDesignDocs (err, docs) ->
                     return callback err if err?
                     async.forEach docs, (doc, cb) ->
-                        async.forEach Object.keys(doc.views), (view, cb) ->
-                            body = doc.views[view]
-                            storeAppView apps, doc, view, body, cb
-                        , (err) ->
-                            removeEmptyView doc, (err) ->
-                                log.error err if err?
-                                cb()
+                        if not doc?.views?
+                            log.warn "Document has no view"
+                            log.warn doc
+                            cb()
+                        else
+                            async.forEach Object.keys(doc.views), (view, cb) ->
+                                body = doc.views[view]
+                                storeAppView apps, doc, view, body, cb
+                            , (err) ->
+                                removeEmptyView doc, (err) ->
+                                    log.error err if err?
+                                    cb()
                     , (err) ->
                         log.error err if err?
                         callback()

    date: true
    prefix: 'lib/request'

# Define random function for application's token
randomString = (length) ->
    string = ""
    while (string.length < length)
        string = string + Math.random().toString(36).substr(2)
    return string.substr 0, length

productionOrTest = process.env.NODE_ENV is "production" or
    process.env.NODE_ENV is "test"

## function create (app, req, views, newView, callback)
## @app {String} application name

## @callback {function} Continuation to pass control back to when complete.
## Store new view with name <app>-request name in case of conflict
## Callback view name (req.req_name or name-req.req_name)
module.exports.create = (app, req, views, newView, callback) ->
    storeRam = (path) ->
        request[app] ?= {}
        request[app]["#{req.type}/#{req.req_name}"] = path
        callback null, path
