How to use the restify.InternalError function in restify

To help you get started, we’ve selected a few restify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github acarl / pg-restify / test / helper.js View on Github external
server.on('uncaughtException', function(req, res, route, err) {
    if (res._headerSent) {
      // If this response was already sent this could be any error.
      // Because domains are weird you could actually have test case
      // validation errors enter this method.
      // If this happens just throw the err.
      throw err;
    }
    log.error(err);
    res.send(new restify.InternalError('Internal error'));
  });
github pcimino / nodejs-restify-mongodb / config / routes-user.js View on Github external
gUser.save(function (err) {
        if (!err) {
          // generate and send a verification code to swap email address
          if (gUser.newEmail) {
            // TODO When messaging is available, add a system message to the user telling them to check their email to verify the email address
            mail.generateVerifyCodeUpdatedEmail(req, res, next, gUser);
          }
          res.send(gUser);
          return next();
        } else {
          var errObj = err;
          if (err.err) { errObj = err.err; }
          return next(new restify.InternalError(errObj));
        }
      });
github Netflix / falcor-restify / lib / index.js View on Github external
return function falcorHandler(req, res, next) {
        var dataSource = getDataSource(req, res);
        var obs,
            paths,
            jsong,
            callParms = {};

        // probably this should be sanity check function?
        if (Object.keys(req.params).length === 0) {
            return next(new restify.InternalError('Request not supported'));
        }
        if (!req.params.method) {
            return next(new restify.InternalError('No query method provided'));
        }
        if (!dataSource[req.params.method]) {
            return next(new restify.InternalError('Data source does not implement the requested method'));
        }
        if (req.params.method === 'set') {
            try {
                jsong = JSON.parse(req.params.jsonGraph);
            }
            catch(e) {
                return next(new restify.InternalError('Unable to parse jsonGraph query string parameter as JSON'));
            }
            obs = dataSource.set(jsong);
        } else if (req.params.method === 'call') {
github pcimino / nodejs-restify-mongodb / config / routes-messaging.js View on Github external
systemMessageArchive.userId = req.session.user;
                 systemMessageArchive.save(function (err, systemMessage) {
                  if (!err) {
                    res.send({});
                  } else {
                    return next(err);
                  }
                });
              } else {
                // already archived
                res.send({});
              }
            } else {
              var errObj = err;
              if (err.err) { errObj = err.err; }
              return next(new restify.InternalError(errObj));
            }
          });
github Netflix / falcor-restify / lib / index.js View on Github external
["arguments", "callPath", "paths", "pathSuffixes"].forEach(function(parameter) {
                try {
                    callParms[parameter] = JSON.parse(req.params[parameter]);
                }
                catch(e) {
                    return next(new restify.InternalError('Unable to parse ' + parameter + ' query string parameter as JSON'));
                }
            });

            obs = dataSource.call(callParms.callPath, callParms.arguments, callParms.pathSuffixes, callParms.paths);
        } else if (req.params.method === 'get') {
            try {
                paths = JSON.parse(req.params.paths);
            }
            catch(e) {
                return next(new restify.InternalError('Unable to parse paths query string parameter as JSON'));
            }
            obs = dataSource.get(paths);
        }
        obs.
            subscribe(
            function(jsonGraph) {
                req.log.debug({data: jsonGraph});
                res.send(200, jsonGraph);
                return next();
            },
            function(err) {
                return next(new restify.InternalError(err));
            });
    };
};
github joyent / node-workflow / lib / api.js View on Github external
}, function (err3, running, running_count) {
                    if (err3) {
                        return next(new restify.InternalError(err3));
                    }
                    return backend.getJobs({
                        execution: 'queued'
                    }, function (err4, queued, queued_count) {
                        if (err4) {
                            return next(new restify.InternalError(err4));
                        }

                        res.header('x-count', count);

                        res.send(200, {
                            service: {
                                name: 'workflow',
                                component: 'jobs',
                                ident: req.headers.host,
                                pid: process.pid
github pcimino / nodejs-restify-mongodb / config / routes-user-signup.js View on Github external
query.count(function(err, count) {
            if (!err) {
               if (count === 0) {
                  res.send({});
                  return next();
               } else {
                  return next(new restify.InternalError('Username already in use.'));
               }
            } else {
              var errObj = err;
              if (err.err) { errObj = err.err; }
              return next(new restify.InternalError(errObj));
            }
         });
      } else {
github Netflix / falcor-restify / lib / index.js View on Github external
function(err) {
                return next(new restify.InternalError(err));
            });
    };
github joyent / manatee / lib / backupServer.js View on Github external
return self._queue.get(req.params.uuid, function (backupJob) {
            if (!backupJob) {
                var err = new restify.ResourceNotFoundError();
                log.info({
                    uuid: req.params.uuid,
                    err: err
                }, 'backup job dne');

                return next(err);
            } else if (backupJob.err) {
                var err2 = new restify.InternalError(backupJob.err);
                log.info({
                    uuid: req.params.uuid,
                    err: err2
                }, 'internal error');

                return next(err2);
            }
            res.send(backupJob);
            return next();
        });
    }
github joyent / node-workflow / lib / api.js View on Github external
return backend.getRunners(function (err2, runners) {
                if (err2) {
                    return next(new restify.InternalError(err2));
                }
                return backend.getJobs({
                    execution: 'running'
                }, function (err3, running, running_count) {
                    if (err3) {
                        return next(new restify.InternalError(err3));
                    }
                    return backend.getJobs({
                        execution: 'queued'
                    }, function (err4, queued, queued_count) {
                        if (err4) {
                            return next(new restify.InternalError(err4));
                        }

                        res.header('x-count', count);