       console.log "DataOp is Delete"
       if task.request.entityId?
         dataOp = 'onDeleteById'
-      else if task.query?
+      else if task.request?.query?
         dataOp = 'onDeleteByQuery'
       else
         dataOp = 'onDeleteAll'

    environmentId = task.appMetadata._id

    convertToError = (body) ->

      errorResult = new Error (body?.message or body.toString())
      errorResult.debugMessage = body.toString()
      errorResult.metadata = metadata
      if body?.unhandledException is true
        errorResult.metadata.unhandled = true

      return errorResult

    completionHandler = (entity) ->

      if task.request?.entityId?
        console.log "GetById"
        dataOp = 'onGetById'
      else if task.request?.query?
        console.log "getByQuery"
        dataOp = 'onGetByQuery'
      else
        console.log "GetAll"
        dataOp = 'onGetAll'
    else if task.method is 'GET' and task.endpoint is '_count'
      if task.request?.query?
        dataOp = 'onGetCountWithQuery'
      else
        dataOp = 'onGetCount'
