Skip to content

Commit

Permalink
fix: rethrow axios errors to consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
x-oflisback committed Sep 22, 2022
1 parent df898d0 commit 5222743
Showing 1 changed file with 34 additions and 49 deletions.
83 changes: 34 additions & 49 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,15 @@ export class Client {

getWorkspaces(): Promise<Workspace[]> {
return new Promise((resolve, reject) => {
try {
this.ensureImpactToken().then(() => {
this.ensureImpactToken()
.then(() => {
this.axios
.get(
`${this.baseUrl}${this.jhUserPath}impact/api/workspaces`
)
.then((response) => resolve(response.data?.data?.items))
})
} catch (e) {
reject(e)
}
.catch((e) => reject(e))
})
}

Expand All @@ -247,8 +245,8 @@ export class Client {
workspaceId: string
}): Promise<ExperimentId> {
return new Promise((resolve, reject) => {
try {
this.ensureImpactToken().then(() => {
this.ensureImpactToken()
.then(() => {
this.axios
.post(
`${this.baseUrl}${this.jhUserPath}impact/api/workspaces/${workspaceId}/experiments`,
Expand All @@ -258,9 +256,7 @@ export class Client {
resolve(response.data.experiment_id)
)
})
} catch (e) {
reject(e)
}
.catch((e) => reject(e))
})
}

Expand All @@ -274,25 +270,22 @@ export class Client {
workspaceId: string
}): Promise<void> {
return new Promise((resolve, reject) => {
try {
this.ensureImpactToken().then(() => {
this.axios
.post(
`${this.baseUrl}${this.jhUserPath}/impact/api/workspaces/${workspaceId}/experiments/${experimentId}/execution`,
{
includeCases: {
ids: cases,
},
options: {
forceCompilation: true,
},
}
)
.then(() => resolve())
})
} catch (e) {
reject(e)
}
this.ensureImpactToken().then(() => {
this.axios
.post(
`${this.baseUrl}${this.jhUserPath}/impact/api/workspaces/${workspaceId}/experiments/${experimentId}/execution`,
{
includeCases: {
ids: cases,
},
options: {
forceCompilation: true,
},
}
)
.then(() => resolve())
.catch((e) => reject(e))
})
})
}

Expand All @@ -304,17 +297,15 @@ export class Client {
workspaceId: string
}): Promise<CompilationStatus> {
return new Promise((resolve, reject) => {
try {
this.ensureImpactToken().then(() => {
this.ensureImpactToken()
.then(() => {
this.axios
.get(
`${this.baseUrl}${this.jhUserPath}/impact/api/workspaces/${workspaceId}/experiments/${experimentId}/execution`
)
.then((response) => resolve(response.data))
})
} catch (e) {
reject(e)
}
.catch((e) => reject(e))
})
}

Expand Down Expand Up @@ -368,17 +359,15 @@ export class Client {

getCustomFunctions(workspaceId: string): Promise<CustomFunction[]> {
return new Promise((resolve, reject) => {
try {
this.ensureImpactToken().then(() => {
this.ensureImpactToken()
.then(() => {
this.axios
.get(
`${this.baseUrl}${this.jhUserPath}impact/api/workspaces/${workspaceId}/custom-functions`
)
.then((response) => resolve(response.data.data.items))
})
} catch (e) {
reject(e)
}
.catch((e) => reject(e))
})
}

Expand All @@ -390,17 +379,15 @@ export class Client {
workspaceId: string
}): Promise<Case[] | undefined> {
return new Promise((resolve, reject) => {
try {
this.ensureImpactToken().then(() => {
this.ensureImpactToken()
.then(() => {
this.axios
.get(
`${this.baseUrl}${this.jhUserPath}impact/api/workspaces/${workspaceId}/experiments/${experimentId}/cases`
)
.then((response) => resolve(response.data?.data?.items))
})
} catch (e) {
reject(e)
}
.catch((e) => reject(e))
})
}

Expand All @@ -416,18 +403,16 @@ export class Client {
workspaceId: string
}): Promise<Trajectories | undefined> {
return new Promise((resolve, reject) => {
try {
this.ensureImpactToken().then(() => {
this.ensureImpactToken()
.then(() => {
this.axios
.post(
`${this.baseUrl}${this.jhUserPath}impact/api/workspaces/${workspaceId}/experiments/${experimentId}/cases/${caseId}/trajectories`,
{ variable_names: variableNames }
)
.then((res) => resolve(res.data))
})
} catch (e) {
reject(e)
}
.catch((e) => reject(e))
})
}
}

0 comments on commit 5222743

Please sign in to comment.