Error: cluster object was closed in couchbase and nodejs

Viewed 714

I am simulating a retrieve function from our database in couchbase and when I try to retreive the data it is showing me this. I've search throughout the net on how to solve this but found none.

Here is the whole error

  Error --------------------------------------------------
 
  Error: cluster object was closed
      at Connection.close (/Users/franzdayrit/_Nobel systems/Projects/valencia-billing/node_modules/couchbase/lib/connection.js:266:24)
      at /Users/franzdayrit/_Nobel systems/Projects/valencia-billing/node_modules/couchbase/lib/cluster.js:612:14

Here is my code using serverless along with couchbase and nodejs

handler.js:

'use strict';

const couchbase = require('couchbase');

//Create base Cluster connection
let cluster = new couchbase.Cluster("couchbase://xxx", {
  username: "xxx",
  password: "xxx"
});

let bucket = cluster.bucket('xxx');

module.exports.retrieve = (event, context, callback) => {
  let qs = "SELECT * FROM xxx WHERE billstatus = 'paid'"
  cluster.query(qs, (error, result) => {
    if(error) {
      return callback({
        statusCode: 500,
        body: JSON.stringify({
          code: error.code,
          message: error.message
        })
      }, null)
    }
    callback(null, {
      statusCode: 200,
      body: JSON.stringify(result)
    })
  })
}

serverless.yml:

service: xxx

frameworkVersion: '2'

provider:
  name: aws
  runtime: nodejs12.x

functions:
  hello:
    handler: handler.hello
    events:
      - http: GET hello
  retrieve:
    handler: handler.retrieve
    events:
      - http: GET retrieve


plugins:
  - serverless-offline
1 Answers

I get the same completely useless error message when I send invalid login credentials. I'm surprised and disappointed that a more specific error isn't thrown. But double/triple check your credentials.

Related