Skip to content

Commit

Permalink
Merge pull request #4 from Paperspace/brodey/errors
Browse files Browse the repository at this point in the history
chore: handle upsert errors
  • Loading branch information
brodeyn authored Mar 14, 2023
2 parents 0ddc0d7 + 1d7a3fb commit 9e23457
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
18 changes: 15 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,21 @@ const getDeploymentByProjectFetcher = fetcher
.create();
function upsertDeployment(config) {
return __awaiter(this, void 0, void 0, function* () {
const { data: deployment } = yield upsertDeploymentFetcher(config);
const { deploymentId } = deployment;
return deploymentId;
try {
const { data: deployment } = yield upsertDeploymentFetcher(config);
const { deploymentId } = deployment;
return deploymentId;
}
catch (e) {
// check which operation threw the exception
if (e instanceof upsertDeploymentFetcher.Error) {
const { data } = e.getActualType();
if ("issues" in data) {
throw new Error(`Error upserting deployment: ${data.message}. Issues: ${JSON.stringify(data.issues)}`);
}
throw new Error(`Error upserting deployment: ${data.message}.`);
}
}
});
}
exports.upsertDeployment = upsertDeployment;
Expand Down
19 changes: 16 additions & 3 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,24 @@ export type LatestRuns =
operations["query.deploymentRunsrouter.get"]["responses"][200]["content"]["application/json"];

export async function upsertDeployment(config: Config) {
const { data: deployment } = await upsertDeploymentFetcher(config);
try {
const { data: deployment } = await upsertDeploymentFetcher(config);

const { deploymentId } = deployment;
const { deploymentId } = deployment;

return deploymentId;
return deploymentId;
} catch(e) {
// check which operation threw the exception
if (e instanceof upsertDeploymentFetcher.Error) {
const { data } = e.getActualType()

if ("issues" in data) {
throw new Error(`Error upserting deployment: ${data.message}. Issues: ${JSON.stringify(data.issues)}`)
}

throw new Error(`Error upserting deployment: ${data.message}.`)
}
}
}

export async function getDeploymentByProjectAndName(
Expand Down

0 comments on commit 9e23457

Please sign in to comment.