If a callback is passed, validate the returned body
356795
function validateBody(err, body) {
      body = tryParse(body);

      if (err || !body) {
        return next(err || new Error('Unparsable response with statusCode ' + statusCode));
      }

      if (statusCode !== 200) {
        return next(new Error(body.message || 'Invalid status code ' + statusCode));
      }

      next(null, body);
    }
806115
function checkBody (expected, actual, matchingRules){
    if(!expected){
        return;
    }
    if(!matchingRules){ //Use v1 style simple matching
        if(! _.isEqual(actual, expected)){
            return {
                error: "Body does not match expectation: ",
                expected: expected,
                actual: actual
            };
        }
    }
    else {
        var paths = Object.keys(matchingRules);
        var failures = paths.map(function(path){
            return v2Ruleset(path, matchingRules[path], actual, expected);
        }).filter(function(f){
            return f !== false;
        });
        if(failures.length){
            return failures[0];
        }
    }
}
390767
function (response, body) {
          var tokenResponse;
          try {
             tokenResponse = self._handlePollingResponse(body);
          } catch (e) {
             self._log.error('Error validating get token response', e, true);
             callback(null, e);
             return;
          }
        
          callback(null, tokenResponse);
       }
182514
function(callback) {
        request.get(this.getStatusUrl(), function(err, res, body) {
            if (err) {
                return callback(err);
            }

            body = body || {};
            body.status = res.statusCode;
            body.date = new Date(body.date);

            callback(err, body, res);
        });

        return this;
    }
1325410
def check(func):
    
    def iCheck(request, *args, **kwargs):
        if not request.method == "POST":
            return HttpResponseBadRequest("Must be POST request.")
        follow = func(request, *args, **kwargs)
        if request.is_ajax():
            return HttpResponse('ok')
        try:
            if 'next' in request.GET:
                return HttpResponseRedirect(request.GET.get('next'))
            if 'next' in request.POST:
                return HttpResponseRedirect(request.POST.get('next'))
            return HttpResponseRedirect(follow.target.get_absolute_url())
        except (AttributeError, TypeError):
            if 'HTTP_REFERER' in request.META:
                return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
            if follow:
                return HttpResponseServerError('"%s" object of type ``%s`` has no method ``get_absolute_url()``.' % (
                    unicode(follow.target), follow.target.__class__))
            return HttpResponseServerError('No follow object and `next` parameter found.')
    return iCheck
1156254
function parseJSON(body, callback) {
  let r = null;
  let err = null;

  try {
    if (typeof body === 'string') {
      r = JSON.parse(body);
    } else {
      r = body;
    }
  } catch(e) {
    err = e;
  }

  return callback(err, r);
}
412576
function(callback) {
                var ret,
                    isFunc  = Util.type.function(callback),
                    args    = [].slice.call(arguments, 1);
               
                if (isFunc)
                    ret     = callback.apply(null, args);
                
                return ret;
            }
283211
def validate(self):
        
        if self.status_code == 200 and self.data.get("ok", False):
            self._logger.debug("Received the following response: %s", self.data)
            return self
        msg = "The request to the Slack API failed."
        raise e.SlackApiError(message=msg, response=self.data)
912727
function validateCallbacks(options) {
            if (options.successCallback && typeof options.successCallback !== 'function') {
                throw new Error(TAG + 'Success callback must be a function.');
            } else {
                options.successCallback = options.successCallback || enplug.noop;
            }

            if (options.errorCallback && typeof options.errorCallback !== 'function') {
                throw new Error(TAG + 'Error callback must be a function.');
            } else {
                options.errorCallback = options.errorCallback || enplug.noop;
            }
        }
1273960
function validationMiddleware (err, req, res, next) {
  if (!err instanceof ValidationError) return next(err);
  return res.status(err.status).send({ errors: err.errors });
}
1009336
function (entity, options, callback) {
                if (entity instanceof Entity) {
                    entity.validate(options, callback);
                } else {
                    callback("parameter is not an entity");
                }
            }
1050308
function makeFormBodyParser(spec) {
  const opts = spec.validate.formOptions || {};
  if (typeof opts.limit === 'undefined') {
    opts.limit = spec.validate.maxBody;
  }
  return async function parseFormBody(ctx, next) {
    if (!ctx.request.is('urlencoded')) {
      return ctx.throw(400, 'expected x-www-form-urlencoded');
    }
    ctx.request.body = ctx.request.body || await parse.form(ctx, opts);
    await next();
  };
}
477784
def validate(self, input_parameters, context):
        """"""
        errors = {}

        for key, type_handler in self.input_transformations.items():
            if self.raise_on_invalid:
                if key in input_parameters:
                    input_parameters[key] = self.initialize_handler(
                        type_handler,
                        input_parameters[key],
                        context=context
                    )
            else:
                try:
                    if key in input_parameters:
                        input_parameters[key] = self.initialize_handler(
                            type_handler,
                            input_parameters[key],
                            context=context
                        )
                except InvalidTypeData as error:
                    errors[key] = error.reasons or str(error.message)
                except Exception as error:
                    if hasattr(error, 'args') and error.args:
                        errors[key] = error.args[0]
                    else:
                        errors[key] = str(error)
        for require in self.required:
            if not require in input_parameters:
                errors[require] = "Required parameter '{}' not supplied".format(require)
        if not errors and getattr(self, 'validate_function', False):
            errors = self.validate_function(input_parameters)
        return errors
881968
function validateObject(job, object, callback) {
		if (typeof object.value === 'undefined') {
			var onLoad = function (err, obj) {
				if (err) {
					job.error = err;
					return callback(err);
				}
				object.value = obj;
				doValidateObject(job, object, callback);
			};
			var opts = {
				timeout: (job.context.options.timeout || 5000)
			};
			//TODO verify http:, file: and plain paths all load properly
			if (object.path) {
				loader.loadPath(object.path, opts, onLoad);
			}
			else if (object.url) {
				loader.load(object.url, opts, onLoad);
			}
			else {
				callback(new Error('object missing value, path or url'));
			}
		}
		else {
			doValidateObject(job, object, callback);
		}
	}
150164
function (method, result) {

      // result should not be undefined
      if (result === undefined) {
        console.warn('JSON-RPC2 response from method ' + methodName + ' should return a result. (JSON-RPC2 spec)')
        result = ''
      }

      var rpcMessage = {
        jsonrpc: '2.0',
        result: result,
        id: id
      }

      callback(rpcMessage)
      responseHasBeenSent = true

    }
164056
function handleNewSharedAddress(body, callbacks){
	if (!ValidationUtils.isArrayOfLength(body.definition, 2))
		return callbacks.ifError("invalid definition");
	if (typeof body.signers !== "object" || Object.keys(body.signers).length === 0)
		return callbacks.ifError("invalid signers");
	if (body.address !== objectHash.getChash160(body.definition))
		return callbacks.ifError("definition doesn't match its c-hash");
	for (var signing_path in body.signers){
		var signerInfo = body.signers[signing_path];
		if (signerInfo.address && !ValidationUtils.isValidAddress(signerInfo.address))
			return callbacks.ifError("invalid member address: "+signerInfo.address);
	}
	determineIfIncludesMe(body.signers, function(err){
		if (err)
			return callbacks.ifError(err);
		validateAddressDefinition(body.definition, function(err){
			if (err)
				return callbacks.ifError(err);
			addNewSharedAddress(body.address, body.definition, body.signers, body.forwarded, callbacks.ifOk);
		});
	});
}
693660
function handleResponse(done, err, response, body) {
  if (err) return done(err, null);
  if (response.statusCode !== 200) return done(new Error(body.msg || 'Unknown error'), null);

  done(null, body);
}