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
16 changes: 13 additions & 3 deletions src/durableClient/DurableClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,21 @@ export class DurableClient implements types.DurableClient {
case 202:
return;
case 404:
return Promise.reject(new Error(`No instance with ID '${instanceId}' found.`));
case 410:
return Promise.reject(
new Error(response.data || `No instance with ID '${instanceId}' found.`)
);
case 412:
return Promise.reject(
new Error(
response.data ||
"The rewind operation is only supported on failed orchestration instances."
)
);
case 501:
return Promise.reject(
new Error(
"The rewind operation is only supported on failed orchestration instances."
response.data ||
"The rewind operation is not supported by the underlying storage provider."
)
);
default:
Expand Down
99 changes: 97 additions & 2 deletions test/unit/orchestrationclient-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,29 @@ describe("Orchestration Client", () => {
expect(result).to.be.equal(undefined);
});

it(`throws when webhook returns invalid status code 404 with webhook error message`, async () => {
const client = new DurableClient(defaultClientInputData);

const testId = "badId";
const testReason = "test";
const expectedWebhookUrl = new url.URL(
defaultClientInputData.managementUrls.rewindPostUri
.replace(TestConstants.idPlaceholder, testId)
.replace(TestConstants.reasonPlaceholder, testReason)
);
const scope = nock(expectedWebhookUrl.origin, requiredPostHeaders)
.post(expectedWebhookUrl.pathname)
.query((actualQueryObject: object) =>
urlQueryEqualsQueryObject(expectedWebhookUrl, actualQueryObject)
)
.reply(404, "No instance ID found!");

await expect(client.rewind(testId, testReason)).to.be.rejectedWith(
"No instance ID found!"
);
expect(scope.isDone()).to.be.equal(true);
});

it(`throws when webhook returns invalid status code 404`, async () => {
const client = new DurableClient(defaultClientInputData);

Expand All @@ -1036,13 +1059,37 @@ describe("Orchestration Client", () => {
)
.reply(404);

// Since the webhook did not provide a response body, use our own custom error message
await expect(client.rewind(testId, testReason)).to.be.rejectedWith(
`No instance with ID '${testId}' found.`
);
expect(scope.isDone()).to.be.equal(true);
});

it(`throws when webhook returns invalid status code 410`, async () => {
it(`throws when webhook returns invalid status code 412 with webhook error message`, async () => {
const client = new DurableClient(defaultClientInputData);

const testId = "badId";
const testReason = "test";
const expectedWebhookUrl = new url.URL(
defaultClientInputData.managementUrls.rewindPostUri
.replace(TestConstants.idPlaceholder, testId)
.replace(TestConstants.reasonPlaceholder, testReason)
);
const scope = nock(expectedWebhookUrl.origin, requiredPostHeaders)
.post(expectedWebhookUrl.pathname)
.query((actualQueryObject: object) =>
urlQueryEqualsQueryObject(expectedWebhookUrl, actualQueryObject)
)
.reply(412, "Precondition failed!");

await expect(client.rewind(testId, testReason)).to.be.rejectedWith(
"Precondition failed!"
);
expect(scope.isDone()).to.be.equal(true);
});

it(`throws when webhook returns invalid status code 412`, async () => {
const client = new DurableClient(defaultClientInputData);

const testId = "badId";
Expand All @@ -1057,14 +1104,62 @@ describe("Orchestration Client", () => {
.query((actualQueryObject: object) =>
urlQueryEqualsQueryObject(expectedWebhookUrl, actualQueryObject)
)
.reply(410);
.reply(412);

// Since the webhook did not provide a response body, use our own custom error message
await expect(client.rewind(testId, testReason)).to.be.rejectedWith(
"The rewind operation is only supported on failed orchestration instances."
);
expect(scope.isDone()).to.be.equal(true);
});

it(`throws when webhook returns invalid status code 501`, async () => {
const client = new DurableClient(defaultClientInputData);

const testId = "badId";
const testReason = "test";
const expectedWebhookUrl = new url.URL(
defaultClientInputData.managementUrls.rewindPostUri
.replace(TestConstants.idPlaceholder, testId)
.replace(TestConstants.reasonPlaceholder, testReason)
);
const scope = nock(expectedWebhookUrl.origin, requiredPostHeaders)
.post(expectedWebhookUrl.pathname)
.query((actualQueryObject: object) =>
urlQueryEqualsQueryObject(expectedWebhookUrl, actualQueryObject)
)
.reply(501, "Invalid storage provider!");

await expect(client.rewind(testId, testReason)).to.be.rejectedWith(
"Invalid storage provider!"
);
expect(scope.isDone()).to.be.equal(true);
});

it(`throws when webhook returns invalid status code 501`, async () => {
const client = new DurableClient(defaultClientInputData);

const testId = "badId";
const testReason = "test";
const expectedWebhookUrl = new url.URL(
defaultClientInputData.managementUrls.rewindPostUri
.replace(TestConstants.idPlaceholder, testId)
.replace(TestConstants.reasonPlaceholder, testReason)
);
const scope = nock(expectedWebhookUrl.origin, requiredPostHeaders)
.post(expectedWebhookUrl.pathname)
.query((actualQueryObject: object) =>
urlQueryEqualsQueryObject(expectedWebhookUrl, actualQueryObject)
)
.reply(501);

// Since the webhook did not provide a response body, use our own custom error message
await expect(client.rewind(testId, testReason)).to.be.rejectedWith(
"The rewind operation is not supported by the underlying storage provider."
);
expect(scope.isDone()).to.be.equal(true);
});

it(`throws when webhook returns invalid status code 500`, async () => {
const client = new DurableClient(defaultClientInputData);

Expand Down