Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Crash on no res #13

@tanaydin

Description

@tanaydin

I'm hammering this with ab, piwik works on a small machine. Sometimes mysql goes offline, and piwik goes too. So no response returns without error and it crashes like this

/Users/xxxxx/Documents/workspace/xxxxx/node_modules/piwik/piwik.js:162
data = res.body;
^
TypeError: Cannot read property 'body' of undefined

I added a control to if there is a res or not.

if (res) {
    try {
        data = JSON.parse (res.body);
        if (data.result && data.result === 'error') {
          error = new Error ('api error');
          error.text = data.message || null;
        }
      }
      catch (e) {
        data = res.body;
      }

      if (res.statusCode >= 300) {
        error = new Error ('http error');
        error.code = res.statusCode;
        error.body = data;
      }
  }

so it stopped crashing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions