loopbackio/strong-error-handler

Support custom jsonSerializer

Open

#8 opened on May 11, 2016

 (0 comments) (0 reactions) (1 assignee)JavaScript (36 forks)auto 404
featurehelp wantedneeds-priority

Repository metrics

Stars
 (38 stars)
PR merge metrics
 (PR metrics pending)

Description

See https://github.com/strongloop/loopback/issues/1650#issuecomment-161920555

  // a custom JSON serializer function for producing JSON response bodies
  // @param sanitizedData: response data containing only safe properties
  // @param originalError: the original Error object
  jsonSerializer: function(sanitizedData, originalError) {
    if (originalError.name === 'ValidationError') {
      var details = sanitizedData.details || {};
      sanitizedData.issueCount =  details.codes && Object.keys(details.codes).length;
    }
    return sanitizedData;
  }

Contributor guide