Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/V2/Parsing/Inference/FailedInferenceResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace Mindee\V2\Parsing\Inference;

use DateTimeImmutable;
use Exception;
use Mindee\V2\Parsing\Error\ErrorResponse;

/**
* Webhook payload returned when an inference fails before producing a result.
*/
class FailedInferenceResponse extends BaseResponse
{
/**
* @var string UUID of the failed inference.
*/
public string $inferenceId;
/**
* @var string UUID of the model used.
*/
public string $modelId;

/**
* @var string Name of the input file.
*/
public string $fileName;

/**
* @var string Alias sent for the file, if any.
*/
public string $fileAlias;

/**
* @var ErrorResponse Problem details for the failure, if available.
*/
public ErrorResponse $error;

/**
* @var DateTimeImmutable Date and time when the inference was started.
*/
public DateTimeImmutable $createdAt;

/**
* @param array<string, int|float|string|bool|null|array<array-key, mixed>> $rawResponse Raw server response array.
* @throws Exception if the date can't be constructed.
*/
public function __construct(array $rawResponse)
{
parent::__construct($rawResponse);

$this->inferenceId = $rawResponse["inference_id"];
$this->modelId = $rawResponse["model_id"];
$this->fileName = $rawResponse["file_name"];
$this->fileAlias = $rawResponse["file_alias"];
$this->error = new ErrorResponse($rawResponse["error"]);
$this->createdAt = new DateTimeImmutable($rawResponse["created_at"]);
}
}
41 changes: 41 additions & 0 deletions tests/V2/Parsing/FailedInferenceResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace V2\Parsing;

use DateTimeImmutable;
use Mindee\V2\Parsing\Error\ErrorResponse;
use Mindee\V2\Parsing\Inference\FailedInferenceResponse;
use PHPUnit\Framework\TestCase;
use TestingUtilities;

require_once(__DIR__ . "/../../TestingUtilities.php");

/**
* Failed Inference Response test
*/
class FailedInferenceResponseTest extends TestCase
{
/**
* Should load.
*/
public function testShouldLoad(): void
{

$fullPath = TestingUtilities::getV2DataDir() . "/errors/webhook_error_500_failed.json";
$content = file_get_contents($fullPath);
$jsonSample = json_decode($content, true);
$response = new FailedInferenceResponse($jsonSample);
self::assertInstanceOf(FailedInferenceResponse::class, $response);
self::assertNotNull($response);
self::assertSame("12345678-1234-1234-1234-123456789ABC", $response->inferenceId);
self::assertSame("default_sample.jpg", $response->fileName);
self::assertSame("dummy-alias.jpg", $response->fileAlias);
self::assertInstanceOf(DateTimeImmutable::class, $response->createdAt);
self::assertNotNull($response->error);
self::assertInstanceOf(ErrorResponse::class, $response->error);
self::assertSame(500, $response->error->status);
self::assertSame("500-012", $response->error->code);
}
}
Loading