keithwhor / nodal

API Services Made Easy With Node.js

Home Page:http://www.nodaljs.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Daemon Error Handling

nsipplswezey opened this issue · comments

commented

Adding some minimal docs to:
nodal/core/required/daemon.js

It's possible I'm misreading something here, but it looks like we have a error in the function signature, but we have err in the function body. I don't obviously see where err is defined, nor do I see where the error argument is used in the method.

Opening an issue to look at this, to see if it's causing an issue I saw on some earlier testing where the server was crashing on an some errors, rather than handling the exception and pausing the server until the error was dealt with.

    /**
    * Error method for handling Daemon errors
    *
    * @param {object} request Request to which to respond with an error
    * @param {object} response Response object to which the error message will be attached
    * @param {object} error Error object to add to the response
    */
    error(req, res, error) {

      res.writeHead(500, {'Content-Type': 'text/plain'});

      res.end(
        JSON.stringify(
          API.error(
            message,
            (process.env.NODE_ENV !== 'production' && err) ?
              err.stack.split('\n') : null
            ),
          null,
          2
        )
      );

commented

Yup. Needs a deeper look.
Error method on the Application class as a signature that makes more sense.

nodal/core/required/application.js

error(req, res, start, status, message, err) {

      status = status || 500;
      message = message || 'Internal Server Error';

      let headers = {'Content-Type': 'application/json'};

      err && console.log(err.stack);

      this.send(
        req,
        res,
        start,
        status,
        headers,
        JSON.stringify(
          API.error(
            message,
            (process.env.NODE_ENV !== 'production' && err) ?
              err.stack.split('\n') : null
          ),
          null,
          2
        ),
        message
      );

    }

  }

The PR for this is really simple, can you submit it?

Nevermind, I did it. Should be fixed. :)

cc03567

commented

Thnx Keith.

Nick

On May 11, 2016, at 3:06 PM, Keith Horwood notifications@github.com wrote:

Closed #240.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub