Update middleware.js

Update validation function to reply with an error instead of an object.