Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hmpo-form-controller

Package Overview
Dependencies
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hmpo-form-controller - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

test/spec/spec.error.js

2

lib/error.js
var _ = require('underscore');
function FormError(key, options) {
function FormError(key, options/*, req*/) {
options = _.extend({

@@ -5,0 +5,0 @@ type: 'default'

@@ -120,5 +120,5 @@ /*eslint no-unused-vars: [2, {"vars": "all", "args": "none"}]*/

if (error.group) {
errors[error.group] = new this.Error(error.group, error);
errors[error.group] = new this.Error(error.group, error, req);
} else {
errors[error.key] = new this.Error(error.key, error);
errors[error.key] = new this.Error(error.key, error, req);
}

@@ -173,7 +173,10 @@ }

var redirect = req.path;
var redirectedError = _.find(err, function (error) {
var redirectError = _.all(err, function (error) {
return error.redirect;
});
if (redirectedError) {
redirect = redirectedError.redirect;
if (redirectError) {
redirect = _.find(err, function (error) {
return error.redirect;
}).redirect;
}

@@ -180,0 +183,0 @@ if (req.baseUrl !== '/') {

{
"name": "hmpo-form-controller",
"version": "0.3.0",
"version": "0.4.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -436,2 +436,25 @@ var Form = require('../../');

it('creates instances of Error class with validation errors', function (done) {
validators.required.returns(false);
req.body = { field: 'value', email: 'foo', name: 'John' };
form.post(req, res, function (err) {
_.each(err, function (e) {
e.should.be.an.instanceOf(form.Error);
});
done();
});
});
it('passes the request object into error constructor', function (done) {
sinon.stub(form, 'Error');
validators.required.returns(false);
req.body = { field: 'value', email: 'foo', name: 'John' };
form.post(req, res, function (err) {
form.Error.should.have.been.calledWithExactly('field', sinon.match({ type: 'required' }), req);
form.Error.should.have.been.calledWithExactly('email', sinon.match({ type: 'required' }), req);
form.Error.should.have.been.calledWithExactly('name', sinon.match({ type: 'required' }), req);
done();
});
});
});

@@ -539,3 +562,12 @@

it('redirects to error redirect if any error has a redirect property', function () {
it('redirects to req.path if not all errors have a redirect value', function () {
err = {
'field-a': new Form.Error('field-a'),
'field-b': new Form.Error('field-b', { redirect: '/exitpage' })
};
form.errorHandler(err, req, res);
res.redirect.should.have.been.calledWith('/index');
});
it('redirects to error redirect if all errors have a redirect value', function () {
err.redirect = '/exitpage';

@@ -542,0 +574,0 @@ form.errorHandler({ field: err }, req, res);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc