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
48 changes: 0 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions src/v2/parsing/inference/failedInferenceResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { parseDate, StringDict } from "@/parsing/index.js";
import { ErrorResponse } from "@/v2/index.js";
import { BaseResponse } from "@/v2/parsing/baseResponse.js";

/**
* Webhook payload returned when an inference fails before producing a result.
*/
export class FailedInferenceResponse extends BaseResponse {
/**
* UUID of the failed inference.
*/
public inferenceId: string;

/**
* UUID of the model used.
*/
public modelId: string;

/**
* Name of the input file.
*/
public fileName: string;

/**
* Alias sent for the file, if any.
*/
public fileAlias?: string;

/**
* Problem details for the failure, if available.
*/
public error: ErrorResponse;

/**
* Date and time when the inference was started.
*/
public createdAt: Date | null;


constructor(serverResponse: StringDict) {
super(serverResponse);
this.inferenceId = serverResponse["inference_id"];
this.modelId = serverResponse["model_id"];
this.fileName = serverResponse["file_name"];
this.fileAlias = serverResponse["file_alias"];
this.error = new ErrorResponse(serverResponse["error"]);
this.createdAt = parseDate(serverResponse["created_at"]);
}
}
3 changes: 3 additions & 0 deletions src/v2/parsing/job/jobResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { BaseResponse } from "@/v2/parsing/baseResponse.js";
import { StringDict } from "@/parsing/stringDict.js";
import { Job } from "./job.js";

/**
* Job response class.
*/
export class JobResponse extends BaseResponse {
/**
* Job for the polling.
Expand Down
2 changes: 1 addition & 1 deletion tests/data
26 changes: 26 additions & 0 deletions tests/v2/parsing/failedInferenceResponse.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import path from "path";
import { ErrorResponse, LocalResponse } from "../../../src/v2/index.js";
import { FailedInferenceResponse } from "../../../src/v2/parsing/inference/failedInferenceResponse.js";
import { V2_RESOURCE_PATH } from "../../index.js";

describe("MindeeV2 - Failed Inference Response", async () => {

it("should load", async () => {

const localResponse = new LocalResponse(path.join(V2_RESOURCE_PATH, "errors", "webhook_error_500_failed.json"));
await localResponse.init();
const response = await localResponse.deserializeResponse(FailedInferenceResponse);

assert.ok(response);
assert.equal(response.inferenceId, "12345678-1234-1234-1234-123456789ABC");
assert.equal(response.fileName, "default_sample.jpg");
assert.equal(response.fileAlias, "dummy-alias.jpg");
assert.ok(response.createdAt);
assert.ok(response.createdAt instanceof Date);
assert.ok(response.error instanceof ErrorResponse);
assert.equal(response.error.status, 500);
assert.equal(response.error.code, "500-012");
});
});
Loading