Skip to content

Commit

Permalink
Merge pull request #159 from mittwald/assertsuccess
Browse files Browse the repository at this point in the history
add assertsuccess func, use for changed route codes
  • Loading branch information
martin-helmich authored Jan 9, 2024
2 parents 60eddfd + 5c83335 commit f9e896f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/commands/cronjob/delete.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertStatus } from "@mittwald/api-client-commons";
import { DeleteBaseCommand } from "../../DeleteBaseCommand.js";
import { Args } from "@oclif/core";
import assertSuccess from "../../lib/assert_success.js";

export default class Delete extends DeleteBaseCommand<typeof Delete> {
static description = "Delete a cron job";
Expand All @@ -20,6 +20,6 @@ export default class Delete extends DeleteBaseCommand<typeof Delete> {
cronjobId,
});

assertStatus(response, 200);
assertSuccess(response);
}
}
4 changes: 2 additions & 2 deletions src/commands/cronjob/execution/abort.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
} from "../../../rendering/process/process_flags.js";
import { ReactNode } from "react";
import { Args } from "@oclif/core";
import { assertStatus } from "@mittwald/api-client-commons";
import { Success } from "../../../rendering/react/components/Success.js";
import { Value } from "../../../rendering/react/components/Value.js";
import assertSuccess from "../../../lib/assert_success.js";

type Result = {
executionId: string;
Expand Down Expand Up @@ -39,7 +39,7 @@ export class Abort extends ExecRenderBaseCommand<typeof Abort, Result> {
executionId,
});

assertStatus(r, 200);
assertSuccess(r);
});

p.complete(
Expand Down
4 changes: 2 additions & 2 deletions src/commands/database/mysql/delete.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertStatus } from "@mittwald/api-client-commons";
import { normalizeProjectIdToUuid } from "../../../Helpers.js";
import { DeleteBaseCommand } from "../../../DeleteBaseCommand.js";
import { mysqlArgs, withMySQLId } from "../../../lib/database/mysql/flags.js";
import assertSuccess from "../../../lib/assert_success.js";

export default class Delete extends DeleteBaseCommand<typeof Delete> {
static description = "Delete a MySQL database";
Expand All @@ -21,7 +21,7 @@ export default class Delete extends DeleteBaseCommand<typeof Delete> {
mysqlDatabaseId,
});

assertStatus(response, 200);
assertSuccess(response);
}

protected mapResourceId(id: string): Promise<string> {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/project/delete.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertStatus } from "@mittwald/api-client-commons";
import { DeleteBaseCommand } from "../../DeleteBaseCommand.js";
import { projectArgs } from "../../lib/project/flags.js";
import assertSuccess from "../../lib/assert_success.js";

export default class Delete extends DeleteBaseCommand<typeof Delete> {
static description = "Delete a project";
Expand All @@ -15,6 +15,6 @@ export default class Delete extends DeleteBaseCommand<typeof Delete> {
projectId,
});

assertStatus(response, 200);
assertSuccess(response);
}
}
12 changes: 12 additions & 0 deletions src/lib/assert_success.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Response, ApiClientError } from "@mittwald/api-client-commons";

export function assertSuccess<T extends Response>(response: T): void {
if (response.status >= 300) {
throw ApiClientError.fromResponse(
`Unexpected response status (expected <300, got: ${response.status})`,
response,
);
}
}

export default assertSuccess;

0 comments on commit f9e896f

Please sign in to comment.