Returns 422 / Unprocessable entity response.

@param int    $code
@param array  $errors
@param string $message

@return \Illuminate\Http\JsonResponse
163262
public function respondValidationError(
        $code = ApiResponse::CODE_VALIDATION_ERROR,
        array $errors = [],
        $message = null
    ): JsonResponse {
        return $this->setStatusCode(IlluminateResponse::HTTP_UNPROCESSABLE_ENTITY)
            ->respond([
                'status' => [
                    'type' => 'error',
                    'message' => $this->getDefaultMessage($code, $message),
                    'code' => $code,
                    'http_code' => $this->getStatusCode(),
                ],
                'errors' => $errors,
            ]);
    }
442143
protected function _error($message, $code)
    {
        header("HTTP/1.0 {$code} {$message}");
        echo $message;

        TableRegistry::get('Field.FieldInstances')->connection()->disconnect();
        exit(0);
    }
319501
protected function sendError(
        int $code,
        string $message,
        $data = null
    ) {
        $response = $this->prepareResponse();

        switch ($code) {
            case static::ERROR_INTERNAL_SERVER:
                $status = HttpResponse::HTTP_INTERNAL_SERVER_ERROR;
                break;

            case static::ERROR_INVALID_CREDENTIALS:
            case static::ERROR_UNAUTHENTICATED:
                $status = HttpResponse::HTTP_UNAUTHORIZED;
                $realm = $this->authentication['realm'] ?? null;
                $auth = 'Basic'
                    . ($realm !== null ? ' realm="' . $realm . '"' : '')
                    . ' charset="UTF-8"';
                $response->headers['WWW-Authenticate'] = $auth;
                break;

            case static::ERROR_INVALID_TOKEN:
                $status = HttpResponse::HTTP_UNAUTHORIZED;
                $realm = $this->authentication['realm'] ?? null;
                $auth = 'Bearer'
                    . ($realm !== null ? ' realm="' . $realm . '"' : '');
                $response->headers['WWW-Authenticate'] = $auth;
                break;

            case static::ERROR_METHOD_NOT_IMPLEMENTED:
                $status = HttpResponse::HTTP_NOT_IMPLEMENTED;
                $response->headers['Allow'] = $data;
                break;

            case static::ERROR_UNAUTHORIZED:
                $status = HttpResponse::HTTP_FORBIDDEN;
                break;

            case static::ERROR_INVALID_RESOURCE:
            case static::ERROR_INVALID_RESOURCE_ID:
            case static::ERROR_INVALID_RESOURCE_OFFSET:
            case static::ERROR_INVALID_RESOURCE_FOREIGN:
            case static::ERROR_INVALID_PAYLOAD:
            case static::ERROR_INVALID_QUERY_PARAMETER:
            case static::ERROR_UNKNOWN_FIELDS:
            case static::ERROR_READONLY_RESOURCE:
            case static::ERROR_FOREIGN_CONSTRAINT:
                $status = HttpResponse::HTTP_BAD_REQUEST;
                break;

            case static::ERROR_RESOURCE_NOT_FOUND:
                $status = HttpResponse::HTTP_NOT_FOUND;
                break;

            case static::ERROR_UNSUPPORTED_MEDIA_TYPE:
                $status = HttpResponse::HTTP_UNSUPPORTED_MEDIA_TYPE;
                break;

            case static::ERROR_METHOD_NOT_ALLOWED:
                $status = HttpResponse::HTTP_METHOD_NOT_ALLOWED;
                if ($data !== null) {
                    $response->headers['Allow'] = $data;
                }
                break;

            case static::ERROR_NOT_ACCEPTABLE:
                $status = HttpResponse::HTTP_NOT_ACCEPTABLE;
                break;

            case static::ERROR_UNKNOWN_ERROR:
            default:
                $actual_code = static::ERROR_UNKNOWN_ERROR;
                $status = HttpResponse::HTTP_INTERNAL_SERVER_ERROR;
                $message = 'Unknown error'
                    . (strlen($message) > 0 ? ': ' . $message : '');
                break;
        }
        $response->status = $status;

        $response->headers['Content-Type'] = 'application/json';
        $response->body = [
            'code' => $code,
            'message' => $message,
        ];

        throw new RouterException($response, $actual_code ?? $code);
    }
302410
protected function getDefaultMessage($code, $message): string
    {
        if ($code !== null && $message === null) {
            return ApiResponse::$statusTexts[$code]['message'];
        }

        return $message;
    }
1082291
public function sendError($message, $code=500) {
        $this->_error = true;
        $statusHeader= "HTTP/1.1 ".$code." ".$message;
        header($statusHeader);
    }
1355105
public function sendError($code, $message = null)
    {
        if ($this->ajaxOnly === false) {
            output()->setContentType('application/json');
        }

        if (is_array($code)) {
            if (is_numeric(key($code))) {
                $message = reset($code);
                $code = key($code);
            } elseif (isset($code[ 'code' ])) {
                $code = $code[ 'code' ];
                $message = $code[ 'message' ];
            }
        }

        output()->sendError($code, $message);
    }
295643
public function jsonError($errorCode, $errorMessage = null)
    {
        // Build error from message
        $error = [
            'type' => 'error',
            'code' => $errorCode,
        ];
        if ($errorMessage) {
            $error['value'] = $errorMessage;
        }

        // Support explicit error handling with status = error, or generic message handling
        // with a message of type = error
        $result = [
            'status' => 'error',
            'errors' => [$error]
        ];
        $response = HTTPResponse::create(json_encode($result), $errorCode)
            ->addHeader('Content-Type', 'application/json');

        // Call a handler method such as onBeforeHTTPError404
        $this->extend("onBeforeJSONError{$errorCode}", $request, $response);

        // Call a handler method such as onBeforeHTTPError, passing 404 as the first arg
        $this->extend('onBeforeJSONError', $errorCode, $request, $response);

        // Throw a new exception
        throw new HTTPResponse_Exception($response);
    }
980449
protected function error ($message = 'invalid request', $code = 0, $httpCode = 0) 
	{
		
		if (is_numeric ($message))
		{
			$error		= new Error ($message);
			$code		= $error->getCode ();
			$message	= $error->getMessage ();
		}
		else if ($message instanceof Error)
		{
			$code		= $message->getCode ();
			$message	= $message->getMessage ();
		}
		
		$this->view->response	= array (
			'success'			=> 0,
			'error_code'		=> $code,
			'error_description'	=> $message
		);
		
		if ($httpCode)
		{
			$this->httpStatus ($httpCode);
		}
		
		return FALSE;
		
	}
155459
public function internalError($msg = '', $errorCode = null, $headers = [])
    {
        return $this->getErrorResponse($msg, $errorCode, self::HTTP_INTERNAL_SERVER_ERROR, $headers);
    }
249637
private static function errorJson($statusCode, $message)
    {
        $output = ['error' => $statusCode];

        if (!empty($message)) {
            $output['message'] = $message;
        }

        return json_encode($output);
    }
441155
public function error($message, $code = 1)
    {
        $this->logger->error($message);

        $this->write($message, self::FC_RED);
        $this->write(PHP_EOL);

        return $code;
    }
238187
protected function convertStatusCode($code, $message, \Exception $exception = null)
    {
        $messageData = json_decode($message, true);

        if (is_array($messageData) && !empty($messageData[JSONConstants::ERROR_EXCEPTION])) {
            $jsonError = $messageData[JSONConstants::ERROR_EXCEPTION];

            if (!empty($messageData[JSONConstants::ERROR_MESSAGE])
                && is_string($messageData[JSONConstants::ERROR_MESSAGE])
            ) {
                $message = $messageData[JSONConstants::ERROR_MESSAGE];
            }

            $exceptionName = '\\Dkd\\PhpCmis\\Exception\\Cmis' . ucfirst($jsonError) . 'Exception';

            if (class_exists($exceptionName)) {
                return new $exceptionName($message, null, $exception);
            }
        }

        if (empty($message) && $exception !== null) {
            $message = $exception->getMessage();
        }

        // fall back to status code
        switch ($code) {
            case 301:
            case 302:
            case 303:
            case 307:
                return new CmisConnectionException(
                    'Redirects are not supported (HTTP status code ' . $code . '): ' . $message,
                    null,
                    $exception
                );
            case 400:
                return new CmisInvalidArgumentException($message, null, $exception);
            case 401:
                return new CmisUnauthorizedException($message, null, $exception);
            case 403:
                return new CmisPermissionDeniedException($message, null, $exception);
            case 404:
                return new CmisObjectNotFoundException($message, null, $exception);
            case 405:
                return new CmisNotSupportedException($message, null, $exception);
            case 407:
                return new CmisProxyAuthenticationException($message, null, $exception);
            case 409:
                return new CmisConstraintException($message, null, $exception);
            default:
                return new CmisRuntimeException($message, null, $exception);
        }
    }
241917
public function json($status_code, $message, $data = null)
    {
        return response()->json([
                                    'status_code' => $status_code,
                                    'message'     => $message,
                                    'data'        => $data,
                                    'request'     => \request()->all(),
                                ]);
    }
1079390
public function abort($message = 'Not authorized.', $config = '', $code = 'error')
	{
		return response()->json([
			'code' => $code,
			'errors' => [
				$code => [
					0 => $message,
				],
			],
			'config' => $config,
		], 430);
	}
857234
protected function response($message, $code)
  {
    Rest::response()->json([
      'status' => $message,
      'code' => $code
    ], $code);

    cancel();
  }
41836
public function response_json($code, $msg, $data, $http_num = 200)
    {

        return response()->json([
            'error' => $code,
            'msg' => $msg,
            'data' => $data,
        ], $http_num);
    }
590689
public function json($code,$message='',$data=[])
    {
        header('Content-type:application/json');
        if(is_array($code)){
            echo json_encode($code);
        }else{
            echo json_encode(['code'=>$code,'message'=>$message,'result'=>$data]);
        }
        exit;
    }