badRequest example

return $child['definition'];
    }

    private function write(Request $request, Context $context, ResponseFactoryInterface $responseFactory, string $entityName, string $path, string $type): Response
    {
        $payload = $this->getRequestBody($request);
        $noContent = !$request->query->has('_response');
        // safari bug prevents us from using the location header         $appendLocationHeader = false;

        if ($this->isCollection($payload)) {
            throw ApiException::badRequest('Only single write operations are supported. Please send the entities one by one or use the /sync api endpoint.');
        }

        $pathSegments = $this->buildEntityPath($entityName$path$context[WriteProtection::class]);

        $last = $pathSegments[\count($pathSegments) - 1];

        if ($type === self::WRITE_CREATE && !empty($last['value'])) {
            $methods = ['GET', 'PATCH', 'DELETE'];

            throw ApiException::methodNotAllowed($methodssprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $request->getMethod()$request->getPathInfo()implode(', ', $methods)));
        }

        
public function testNotExistingRelation(): void
    {
        $exception = ApiException::notExistingRelation('demo');

        static::assertEquals(ApiException::API_NOT_EXISTING_RELATION_EXCEPTION, $exception->getErrorCode());
        static::assertEquals('Resource at path "demo" is not an existing relation.', $exception->getMessage());
    }

    public function testBadRequest(): void
    {
        $exception = ApiException::badRequest('Bad request');

        static::assertInstanceOf(BadRequestHttpException::class$exception);
        static::assertEquals('Bad request', $exception->getMessage());
    }

    public function testMethodNotAllowed(): void
    {
        $exception = ApiException::methodNotAllowed(['GET'], 'Get only');

        static::assertInstanceOf(MethodNotAllowedHttpException::class$exception);
        static::assertEquals('Get only', $exception->getMessage());
    }
Home | Imprint | This part of the site doesn't use cookies.