infeeeee / kimai2-cmd

Command line client for Kimai2, the open source, self-hosted time tracker
MIT License
24 stars 6 forks source link

Cannot read property 'body' of undefined #29

Closed jonahbohlmann closed 1 year ago

jonahbohlmann commented 1 year ago

Hello,

I have the latest Kimai version with a certificate from internal CA (so untrusted by new devices) which is trusted on my PC.

I use Linux Ubuntu 22.04 as OS.

Installed CLI tool version: 1.3.0

When I try to use this CLI tool, I get this error:

>> kimai2-cmd -v
No environment variable found
Looking for settings.ini in the following places:
{ pkg: '/home/jonah/.local/bin', npm: '/snapshot/kimai2-cmd' }
settings.ini found at: /home/jonah/.local/bin/settings.ini

? Select command Start new measurement
selected answer: start
---
calling kimai:  GET projects [object Object]
request options: [object Object]
/snapshot/kimai2-cmd/kimai2-cmd.js:84
            let jsonarr = JSON.parse(response.body)
                                              ^

TypeError: Cannot read property 'body' of undefined
    at Request.request [as _callback] (/snapshot/kimai2-cmd/kimai2-cmd.js:84:47)
    at Request.init.self.callback (/snapshot/kimai2-cmd/node_modules/request/request.js:185:22)
    at Request.emit (events.js:198:13)
    at Request.onRequestError (/snapshot/kimai2-cmd/node_modules/request/request.js:881:8)
    at ClientRequest.emit (events.js:198:13)
    at TLSSocket.socketErrorListener (_http_client.js:401:9)
    at TLSSocket.emit (events.js:198:13)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Any idea?

infeeeee commented 1 year ago

The error means you don't get a response from your Kimai instance.

1. Make sure the problem is with kimai2-cmd, not with your install

Can you access the api page in your browser? It should be /api/doc at the end of the url.

You should see the same thing as on the demo page: https://demo.kimai.org/api/doc Login with the demo credentials: https://www.kimai.org/demo/

Other tools are working? Just to make sure it's not a problem with your server install but with clients.

2. If everything is working as expected except for kima2-cmd:

request package used by this app has options for assigning specific certificates to a call, I guess your cert should be added this way as in the documentation: https://www.npmjs.com/package/request#tlsssl-protocol

It shouldn't be that much work, but I can't test it, also I don't use kimai nowadays, so I won't implement it. If you write it, test it, I would be very happy to accept your PR.

m0ark commented 1 year ago

Hi,

I faced the same issue and implemented the required changes: https://github.com/infeeeee/kimai2-cmd/pull/33

Feel free to request changes if you are not happy with it.

infeeeee commented 1 year ago

closed by #33