+ var missingMsg ='error: could not validate, could not find assertion in `data` field';

+ var status =200;

+ var fields = {};

+

+ if (!assertion) {

+ status =400;

+ fields = { general: missingMsg };

+ }

+ else {

+ try {

+ status =200;

+ var o =JSON.parse(assertion);

+ if (!o.badge) o.badge= {}

+ if (!o.badge.issuer) o.badge.issuer= {}

+ var errors =Badge.validateBody( o );

+ if (errors) {

+ fields =errors.fields;

+ status =400;

+ }

+ }

+

+ catch (err) {

+ status =500;

+ if (err.name==="SyntaxError") {

+ fields = { general:"Could not parse this JSON blob. Make sure it is well formed and try again!" }

+ } else {

+ fields = { general:err.name+": "+err.message }

+ }

+ }

+ }

+

+ functionhumanize (value, field) {

+ var url ='Must either be a fully qualified URL (<code>http://example.com/path/evidence.html</code>) or begin with a forward slash (<code>/path/evidence.html</code>). <br> Non-qualified URLs will be prefixed with the origin specified in <code>badge.issuer.origin</code>';

+ var length ='Cannot be longer than 128 characters'

+ var msgs = {

+ recipient:'Must be an email address (<code>someone@example.com</code>) or a hash (<code>sha256$1234567890abcdef</code>)',

+ evidence: url,

+ "badge.version":'Must be in the form of <code>x.y</code> or <code>x.y.z</code>',