Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The search example from the README yields internal server error #13

Closed
RKrahl opened this issue Jan 22, 2020 · 3 comments
Closed

The search example from the README yields internal server error #13

RKrahl opened this issue Jan 22, 2020 · 3 comments

Comments

@RKrahl
Copy link
Contributor

RKrahl commented Jan 22, 2020

Describe the bug
When trying the search example query, the server replies with a 500 "Internal Server Error"

To Reproduce
Steps to reproduce the behavior, follow the instructions from the README:

  1. git clone git@github.com:panosc-eu/search-api.git
  2. cd search-api
  3. npm install
  4. npm start
  5. Wait for the message Server is running at http://134.30.210.106:3000 to appear.
  6. In a second terminal: curl -g -X GET "http://134.30.210.106:3000/datasets?filter[where][pressure.value][gt]=50&filter[limit]=10&filter[skip]=0" -H "accept: application/json"

Expected behavior
Expected to see some search result in the second terminal.

Screenshots
The output from the curl command in the second terminal is:
{"error":{"statusCode":500,"message":"Internal Server Error"}}

The first terminal running the npm start command shows a trace log:

Unhandled error in GET /datasets?filter[where][pressure.value][gt]=50&filter[limit]=10&filter[skip]=0: 500 Error: Unit not recognized
    at new QtyError (/net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/node_modules/js-quantities/build/quantities.js:180:17)
    at parseUnits (/net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/node_modules/js-quantities/build/quantities.js:794:13)
    at Qty.parse (/net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/node_modules/js-quantities/build/quantities.js:748:24)
    at new Qty (/net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/node_modules/js-quantities/build/quantities.js:872:13)
    at convertUnits (/net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/src/repositories/dataset.repository.ts:37:15)
    at processQuery (/net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/src/repositories/dataset.repository.ts:67:11)
    at DatasetRepository.modelClass.observe (/net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/src/repositories/dataset.repository.ts:26:31)
    at notifySingleObserver (/net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/node_modules/loopback-datasource-juggler/lib/observer.js:162:24)
    at /net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/node_modules/async/dist/async.js:3110:16
    at replenish (/net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/node_modules/async/dist/async.js:1011:17)
    at /net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/node_modules/async/dist/async.js:1016:9
    at eachLimit$1 (/net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/node_modules/async/dist/async.js:3196:24)
    at Object.<anonymous> (/net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/node_modules/async/dist/async.js:1046:16)
    at doNotify (/net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/node_modules/loopback-datasource-juggler/lib/observer.js:159:11)
    at doNotify (/net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/node_modules/loopback-datasource-juggler/lib/observer.js:157:49)
    at Function.ObserverMixin._notifyBaseObservers (/net/home/jsi/ExPaNDS/PaNOSC-WP3/search-api/node_modules/loopback-datasource-juggler/lib/observer.js:180:5)

Desktop (please complete the following information):

  • OS: openSUSE 15.1
  • npm --version: 6.9.0
  • node --version: v10.16.3
@garethcmurphy
Copy link
Contributor

hi @RKrahl
can you try
npx ts-node ./exampleQuery.ts

@RKrahl
Copy link
Contributor Author

RKrahl commented Jan 23, 2020

You mean in the second terminal in the place of the curl call?

On my desktop, it does not work, because the npm start binds at the external IP address of my box, while npx ts-node ./exampleQuery.ts tries to connect to localhost and gets a connection refused. I have no idea how to control this.

In the meanwhile, I built a dockerized version (rkrahl/nodejs:12.14.1 on Docker Hub). There, the result is curious:

If I run npx ts-node ./exampleQuery.ts once in the second terminal, I get

{
  "where": {
    "and": [
      {
        "variable": "temperature",
        "operator": "gt",
        "value": 0,
        "unit": "degC"
      },
      {
        "variable": "pressure",
        "operator": "gt",
        "value": 7000000,
        "unit": "kg/m*s2"
      }
    ]
  }
}
http://localhost:3000/datasets?filter=%7B%22where%22%3A%7B%22and%22%3A%5B%7B%22variable%22%3A%22temperature%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A0%2C%22unit%22%3A%22degC%22%7D%2C%7B%22variable%22%3A%22pressure%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A7000000%2C%22unit%22%3A%22kg%2Fm*s2%22%7D%5D%7D%7D
[]

as output and

Try http://[::1]:3000/ping
{ 'temperature.value': { gt: 0 } }
{ 'pressure.value': { gt: 7000000 } }
[
  { 'temperature.value': { gt: 0 } },
  { 'pressure.value': { gt: 7000000 } }
]

in the log of the npm start process.

If I run the very same call a second time, I get:

{
  "where": {
    "and": [
      {
        "variable": "temperature",
        "operator": "gt",
        "value": 0,
        "unit": "degC"
      },
      {
        "variable": "pressure",
        "operator": "gt",
        "value": 7000000,
        "unit": "kg/m*s2"
      }
    ]
  }
}
http://localhost:3000/datasets?filter=%7B%22where%22%3A%7B%22and%22%3A%5B%7B%22variable%22%3A%22temperature%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A0%2C%22unit%22%3A%22degC%22%7D%2C%7B%22variable%22%3A%22pressure%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A7000000%2C%22unit%22%3A%22kg%2Fm*s2%22%7D%5D%7D%7D
StatusCodeError: 500 - "{\"error\":{\"statusCode\":500,\"message\":\"Internal Server Error\"}}"
    at new StatusCodeError (/usr/lib/nodejs/search-api/node_modules/request-promise-core/lib/errors.js:32:15)
    at Request.plumbing.callback (/usr/lib/nodejs/search-api/node_modules/request-promise-core/lib/plumbing.js:104:33)
    at Request.RP$callback [as _callback] (/usr/lib/nodejs/search-api/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at Request.self.callback (/usr/lib/nodejs/search-api/node_modules/request/request.js:185:22)
    at Request.emit (events.js:223:5)
    at Request.EventEmitter.emit (domain.js:475:20)
    at Request.<anonymous> (/usr/lib/nodejs/search-api/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:223:5)
    at Request.EventEmitter.emit (domain.js:475:20)
    at IncomingMessage.<anonymous> (/usr/lib/nodejs/search-api/node_modules/request/request.js:1083:12) {
  name: 'StatusCodeError',
  statusCode: 500,
  message: '500 - "{\\"error\\":{\\"statusCode\\":500,\\"message\\":\\"Internal Server Error\\"}}"',
  error: '{"error":{"statusCode":500,"message":"Internal Server Error"}}',
  options: {
    uri: 'http://localhost:3000/datasets?filter=%7B%22where%22%3A%7B%22and%22%3A%5B%7B%22variable%22%3A%22temperature%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A0%2C%22unit%22%3A%22degC%22%7D%2C%7B%22variable%22%3A%22pressure%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A7000000%2C%22unit%22%3A%22kg%2Fm*s2%22%7D%5D%7D%7D',
    method: 'GET',
    callback: [Function: RP$callback],
    transform: undefined,
    simple: true,
    resolveWithFullResponse: false,
    transform2xxOnly: false
  },
  response: IncomingMessage {
    _readableState: ReadableState {
      objectMode: false,
      highWaterMark: 16384,
      buffer: BufferList { head: null, tail: null, length: 0 },
      length: 0,
      pipes: null,
      pipesCount: 0,
      flowing: true,
      ended: true,
      endEmitted: true,
      reading: false,
      sync: true,
      needReadable: false,
      emittedReadable: false,
      readableListening: false,
      resumeScheduled: false,
      paused: false,
      emitClose: true,
      autoDestroy: false,
      destroyed: false,
      defaultEncoding: 'utf8',
      awaitDrain: 0,
      readingMore: true,
      decoder: null,
      encoding: null
    },
    readable: false,
    _events: [Object: null prototype] {
      end: [Array],
      close: [Array],
      data: [Function],
      error: [Function]
    },
    _eventsCount: 4,
    _maxListeners: undefined,
    socket: Socket {
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'localhost',
      _readableState: [ReadableState],
      readable: true,
      _events: [Object: null prototype],
      _eventsCount: 6,
      _maxListeners: undefined,
      _writableState: [WritableState],
      writable: false,
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: null,
      _server: null,
      parser: null,
      _httpMessage: [ClientRequest],
      [Symbol(asyncId)]: 13,
      [Symbol(kHandle)]: [TCP],
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0
    },
    connection: Socket {
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'localhost',
      _readableState: [ReadableState],
      readable: true,
      _events: [Object: null prototype],
      _eventsCount: 6,
      _maxListeners: undefined,
      _writableState: [WritableState],
      writable: false,
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: null,
      _server: null,
      parser: null,
      _httpMessage: [ClientRequest],
      [Symbol(asyncId)]: 13,
      [Symbol(kHandle)]: [TCP],
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0
    },
    httpVersionMajor: 1,
    httpVersionMinor: 1,
    httpVersion: '1.1',
    complete: true,
    headers: {
      'x-powered-by': 'Express',
      'access-control-allow-origin': '*',
      'access-control-allow-credentials': 'true',
      'x-content-type-options': 'nosniff',
      'content-type': 'application/json; charset=utf-8',
      date: 'Thu, 23 Jan 2020 14:29:58 GMT',
      connection: 'close',
      'content-length': '62'
    },
    rawHeaders: [
      'X-Powered-By',
      'Express',
      'Access-Control-Allow-Origin',
      '*',
      'Access-Control-Allow-Credentials',
      'true',
      'X-Content-Type-Options',
      'nosniff',
      'Content-Type',
      'application/json; charset=utf-8',
      'Date',
      'Thu, 23 Jan 2020 14:29:58 GMT',
      'Connection',
      'close',
      'Content-Length',
      '62'
    ],
    trailers: {},
    rawTrailers: [],
    aborted: false,
    upgrade: false,
    url: '',
    method: null,
    statusCode: 500,
    statusMessage: 'Internal Server Error',
    client: Socket {
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'localhost',
      _readableState: [ReadableState],
      readable: true,
      _events: [Object: null prototype],
      _eventsCount: 6,
      _maxListeners: undefined,
      _writableState: [WritableState],
      writable: false,
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: null,
      _server: null,
      parser: null,
      _httpMessage: [ClientRequest],
      [Symbol(asyncId)]: 13,
      [Symbol(kHandle)]: [TCP],
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0
    },
    _consuming: false,
    _dumped: false,
    req: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      socket: [Socket],
      connection: [Socket],
      _header: 'GET /datasets?filter=%7B%22where%22%3A%7B%22and%22%3A%5B%7B%22variable%22%3A%22temperature%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A0%2C%22unit%22%3A%22degC%22%7D%2C%7B%22variable%22%3A%22pressure%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A7000000%2C%22unit%22%3A%22kg%2Fm*s2%22%7D%5D%7D%7D HTTP/1.1\r\n' +
        'host: localhost:3000\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      path: '/datasets?filter=%7B%22where%22%3A%7B%22and%22%3A%5B%7B%22variable%22%3A%22temperature%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A0%2C%22unit%22%3A%22degC%22%7D%2C%7B%22variable%22%3A%22pressure%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A7000000%2C%22unit%22%3A%22kg%2Fm*s2%22%7D%5D%7D%7D',
      _ended: true,
      res: [Circular],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      [Symbol(kNeedDrain)]: false,
      [Symbol(isCorked)]: false,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    request: Request {
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      uri: [Url],
      method: 'GET',
      readable: true,
      writable: true,
      explicitMethod: true,
      _qs: [Querystring],
      _auth: [Auth],
      _oauth: [OAuth],
      _multipart: [Multipart],
      _redirect: [Redirect],
      _tunnel: [Tunnel],
      _rp_resolve: [Function],
      _rp_reject: [Function],
      _rp_promise: [Promise],
      _rp_callbackOrig: undefined,
      callback: [Function],
      _rp_options: [Object],
      headers: {},
      setHeader: [Function],
      hasHeader: [Function],
      getHeader: [Function],
      removeHeader: [Function],
      localAddress: undefined,
      pool: {},
      dests: [],
      __isRequestRequest: true,
      _callback: [Function: RP$callback],
      proxy: null,
      tunnel: false,
      setHost: true,
      originalCookieHeader: undefined,
      _disableCookies: true,
      _jar: undefined,
      port: '3000',
      host: 'localhost',
      path: '/datasets?filter=%7B%22where%22%3A%7B%22and%22%3A%5B%7B%22variable%22%3A%22temperature%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A0%2C%22unit%22%3A%22degC%22%7D%2C%7B%22variable%22%3A%22pressure%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A7000000%2C%22unit%22%3A%22kg%2Fm*s2%22%7D%5D%7D%7D',
      httpModule: [Object],
      agentClass: [Function],
      agent: [Agent],
      _started: true,
      href: 'http://localhost:3000/datasets?filter=%7B%22where%22%3A%7B%22and%22%3A%5B%7B%22variable%22%3A%22temperature%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A0%2C%22unit%22%3A%22degC%22%7D%2C%7B%22variable%22%3A%22pressure%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A7000000%2C%22unit%22%3A%22kg%2Fm*s2%22%7D%5D%7D%7D',
      req: [ClientRequest],
      ntick: true,
      response: [Circular],
      originalHost: 'localhost:3000',
      originalHostHeaderName: 'host',
      responseContent: [Circular],
      _destdata: true,
      _ended: true,
      _callbackCalled: true
    },
    toJSON: [Function: responseToJSON],
    caseless: Caseless { dict: [Object] },
    body: '{"error":{"statusCode":500,"message":"Internal Server Error"}}'
  }
}

as output and

{ 'temperature.value': { gt: 0 } }
{ 'pressure.value': { gt: 7000000 } }
[
  { 'temperature.value': { gt: 0 } },
  { 'pressure.value': { gt: 7000000 } }
]

Unhandled error in GET /datasets?filter=%7B%22where%22%3A%7B%22and%22%3A%5B%7B%22variable%22%3A%22temperature%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A0%2C%22unit%22%3A%22degC%22%7D%2C%7B%22variable%22%3A%22pressure%22%2C%22operator%22%3A%22gt%22%2C%22value%22%3A7000000%2C%22unit%22%3A%22kg%2Fm*s2%22%7D%5D%7D%7D: 500 Error: Unit not recognized
    at new QtyError (/usr/lib/nodejs/search-api/node_modules/js-quantities/build/quantities.js:180:17)
    at parseUnits (/usr/lib/nodejs/search-api/node_modules/js-quantities/build/quantities.js:794:13)
    at Qty.parse (/usr/lib/nodejs/search-api/node_modules/js-quantities/build/quantities.js:748:24)
    at new Qty (/usr/lib/nodejs/search-api/node_modules/js-quantities/build/quantities.js:872:13)
    at convertUnits (/usr/lib/nodejs/search-api/src/repositories/dataset.repository.ts:37:15)
    at processQuery (/usr/lib/nodejs/search-api/src/repositories/dataset.repository.ts:67:11)
    at /usr/lib/nodejs/search-api/src/repositories/dataset.repository.ts:26:31
    at notifySingleObserver (/usr/lib/nodejs/search-api/node_modules/loopback-datasource-juggler/lib/observer.js:162:24)
    at /usr/lib/nodejs/search-api/node_modules/async/dist/async.js:3110:16
    at replenish (/usr/lib/nodejs/search-api/node_modules/async/dist/async.js:1011:17)
    at iterateeCallback (/usr/lib/nodejs/search-api/node_modules/async/dist/async.js:995:17)
    at /usr/lib/nodejs/search-api/node_modules/async/dist/async.js:969:16
    at /usr/lib/nodejs/search-api/node_modules/loopback-datasource-juggler/lib/observer.js:165:26
    at processTicksAndRejections (internal/process/task_queues.js:94:5)

in the log of the npm start process.

@garethcmurphy
Copy link
Contributor

This should be working now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants