diff --git a/src/Contracts/DataModels.ts b/src/Contracts/DataModels.ts index ca76351cf..a367656e4 100644 --- a/src/Contracts/DataModels.ts +++ b/src/Contracts/DataModels.ts @@ -450,21 +450,21 @@ export interface IResponse { data: T; } -export interface IValidationError { +export interface IPhoenixError { message: string; type: string; } -export interface IMaxAllocationTimeExceeded extends IValidationError { +export interface IMaxAllocationTimeExceeded extends IPhoenixError { earliestAllocationTimestamp: string; maxAllocationTimePerDayPerUserInMinutes: string; } -export interface IMaxDbAccountsPerUserExceeded extends IValidationError { +export interface IMaxDbAccountsPerUserExceeded extends IPhoenixError { maxSimultaneousConnectionsPerUser: string; } -export interface IMaxUsersPerDbAccountExceeded extends IValidationError { +export interface IMaxUsersPerDbAccountExceeded extends IPhoenixError { maxSimultaneousUsersPerDbAccount: string; } @@ -557,4 +557,5 @@ export enum PhoenixErrorType { AllocationValidationResult = "AllocationValidationResult", RegionNotServicable = "RegionNotServicable", SubscriptionNotAllowed = "SubscriptionNotAllowed", + UnknownError = "UnknownError", } diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index a74abb0d9..a90b0dc41 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -369,9 +369,6 @@ export default class Explorer { }); useNotebook.getState().setIsAllocating(true); connectionInfo = await this.phoenixClient.allocateContainer(provisionData); - if (connectionInfo.status !== HttpStatusCodes.OK) { - throw new Error(`Received status code: ${connectionInfo?.status}`); - } if (!connectionInfo?.data?.notebookServerUrl) { throw new Error(`NotebookServerUrl is invalid!`); } @@ -382,6 +379,7 @@ export default class Explorer { } catch (error) { TelemetryProcessor.traceFailure(Action.PhoenixConnection, { dataExplorerArea: Areas.Notebook, + status: error.status, error: getErrorMessage(error), errorStack: getErrorStack(error), }); diff --git a/src/Phoenix/PhoenixClient.ts b/src/Phoenix/PhoenixClient.ts index 7629ffac5..3b95a5786 100644 --- a/src/Phoenix/PhoenixClient.ts +++ b/src/Phoenix/PhoenixClient.ts @@ -21,9 +21,9 @@ import { IMaxDbAccountsPerUserExceeded, IMaxUsersPerDbAccountExceeded, IPhoenixConnectionInfoResult, + IPhoenixError, IProvisionData, IResponse, - IValidationError, PhoenixErrorType, } from "../Contracts/DataModels"; import { useNotebook } from "../Explorer/Notebook/useNotebook"; @@ -59,17 +59,19 @@ export class PhoenixClient { body: JSON.stringify(provisionData), }); const responseJson = await response?.json(); - if (response.status === HttpStatusCodes.Forbidden) { - throw new Error(this.ConvertToForbiddenErrorString(responseJson)); + if (response.ok) { + return { + status: response.status, + data: responseJson, + }; } - return { - status: response.status, - data: responseJson, - }; + const phoenixError = responseJson as IPhoenixError; + if (response.status === HttpStatusCodes.Forbidden) { + throw new Error(this.ConvertToForbiddenErrorString(phoenixError)); + } + throw new Error(phoenixError.message); } catch (error) { - if (response.status === HttpStatusCodes.Forbidden) { - error.status = HttpStatusCodes.Forbidden; - } + error.status = response?.status; throw error; } } @@ -220,7 +222,7 @@ export class PhoenixClient { }; } - public ConvertToForbiddenErrorString(jsonData: IValidationError): string { + public ConvertToForbiddenErrorString(jsonData: IPhoenixError): string { const errInfo = jsonData; switch (errInfo?.type) { case PhoenixErrorType.MaxAllocationTimeExceeded: {