UnprocessableHttpEntityException example

$violations->filterByFields(
        array_diff(array_keys($entity->getFieldDefinitions())$field_names)
      );
    }

    if (count($violations) > 0) {
      // Instead of returning a generic 400 response we use the more specific       // 422 Unprocessable Entity code from RFC 4918. That way clients can       // distinguish between general syntax errors in bad serializations (code       // 400) and semantic errors in well-formed requests (code 422).       // @see \Drupal\jsonapi\Normalizer\UnprocessableHttpEntityExceptionNormalizer       $exception = new UnprocessableHttpEntityException();
      $exception->setViolations($violations);
      throw $exception;
    }
  }

}
Home | Imprint | This part of the site doesn't use cookies.