@shapediver/sdk.geometry-api-sdk-v2
Advanced tools
Comparing version 1.4.1 to 1.5.0
@@ -5,2 +5,3 @@ export * from "@shapediver/api.geometry-api-dto-v2"; | ||
export { create, ShapeDiverSdk } from "./ShapeDiverSdk"; | ||
export { isGBError, isGBGenericError, isGBRequestError, isGBResponseError, } from "./utils/utils"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -17,3 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ShapeDiverSdk = exports.create = exports.ShapeDiverResponseError = exports.ShapeDiverSdkConfigType = exports.ShapeDiverSdkApiResponseType = exports.ShapeDiverRequestError = exports.ShapeDiverError = void 0; | ||
exports.isGBResponseError = exports.isGBRequestError = exports.isGBGenericError = exports.isGBError = exports.ShapeDiverSdk = exports.create = exports.ShapeDiverResponseError = exports.ShapeDiverSdkConfigType = exports.ShapeDiverSdkApiResponseType = exports.ShapeDiverRequestError = exports.ShapeDiverError = void 0; | ||
__exportStar(require("@shapediver/api.geometry-api-dto-v2"), exports); | ||
@@ -30,2 +30,7 @@ var sdk_geometry_api_sdk_core_1 = require("@shapediver/sdk.geometry-api-sdk-core"); | ||
Object.defineProperty(exports, "ShapeDiverSdk", { enumerable: true, get: function () { return ShapeDiverSdk_1.ShapeDiverSdk; } }); | ||
var utils_1 = require("./utils/utils"); | ||
Object.defineProperty(exports, "isGBError", { enumerable: true, get: function () { return utils_1.isGBError; } }); | ||
Object.defineProperty(exports, "isGBGenericError", { enumerable: true, get: function () { return utils_1.isGBGenericError; } }); | ||
Object.defineProperty(exports, "isGBRequestError", { enumerable: true, get: function () { return utils_1.isGBRequestError; } }); | ||
Object.defineProperty(exports, "isGBResponseError", { enumerable: true, get: function () { return utils_1.isGBResponseError; } }); | ||
//# sourceMappingURL=index.js.map |
import { ShapeDiverResponseError as ShapeDiverResponseErrorDto, ShapeDiverResponseErrorType } from "@shapediver/api.geometry-api-dto-v2"; | ||
import { ShapeDiverError, ShapeDiverResponseError as ShapeDiverResponseErrorCore } from "@shapediver/sdk.geometry-api-sdk-core"; | ||
import { ShapeDiverError, ShapeDiverErrorType, ShapeDiverResponseError as ShapeDiverResponseErrorCore } from "@shapediver/sdk.geometry-api-sdk-core"; | ||
export declare class ShapeDiverResponseError extends ShapeDiverError implements ShapeDiverResponseErrorDto { | ||
readonly errorType: ShapeDiverErrorType; | ||
readonly status: number; | ||
@@ -5,0 +6,0 @@ readonly error: ShapeDiverResponseErrorType; |
@@ -10,2 +10,3 @@ "use strict"; | ||
super(e.message); | ||
this.errorType = sdk_geometry_api_sdk_core_1.ShapeDiverErrorType.Response; | ||
this.status = e.status; | ||
@@ -12,0 +13,0 @@ this.desc = e.desc; |
@@ -0,1 +1,11 @@ | ||
import { ShapeDiverError, ShapeDiverRequestError as ShapeDiverRequestErrorCore } from "@shapediver/sdk.geometry-api-sdk-core"; | ||
import { ShapeDiverResponseError } from "../ShapeDiverErrors"; | ||
/** Type guard for all error types of the Geometry Backend SDK package. */ | ||
export declare function isGBError(e: any): e is (ShapeDiverError & ShapeDiverRequestErrorCore & ShapeDiverResponseError); | ||
/** Type guard for a Geometry Backend SDK generic error. */ | ||
export declare function isGBGenericError(e: any): e is ShapeDiverError; | ||
/** Type guard for a Geometry Backend SDK request error. */ | ||
export declare function isGBRequestError(e: any): e is ShapeDiverRequestErrorCore; | ||
/** Type guard for a Geometry Backend SDK response error. */ | ||
export declare function isGBResponseError(e: any): e is ShapeDiverResponseError; | ||
/** | ||
@@ -2,0 +12,0 @@ * Sends the given request, handles retries for the HTTP status 429, and maps |
@@ -12,5 +12,33 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.encodeBase64 = exports.sleep = exports.sendRequest = void 0; | ||
exports.encodeBase64 = exports.sleep = exports.sendRequest = exports.isGBResponseError = exports.isGBRequestError = exports.isGBGenericError = exports.isGBError = void 0; | ||
const sdk_geometry_api_sdk_core_1 = require("@shapediver/sdk.geometry-api-sdk-core"); | ||
const ShapeDiverErrors_1 = require("../ShapeDiverErrors"); | ||
/** Type guard for all error types of the Geometry Backend SDK package. */ | ||
function isGBError(e) { | ||
return e instanceof Error && | ||
"errorType" in e && | ||
Object.values(sdk_geometry_api_sdk_core_1.ShapeDiverErrorType).includes(e.errorType); | ||
} | ||
exports.isGBError = isGBError; | ||
/** Type guard for a Geometry Backend SDK generic error. */ | ||
function isGBGenericError(e) { | ||
return e instanceof Error && | ||
"errorType" in e && | ||
e.errorType === sdk_geometry_api_sdk_core_1.ShapeDiverErrorType.Generic; | ||
} | ||
exports.isGBGenericError = isGBGenericError; | ||
/** Type guard for a Geometry Backend SDK request error. */ | ||
function isGBRequestError(e) { | ||
return e instanceof Error && | ||
"errorType" in e && | ||
e.errorType === sdk_geometry_api_sdk_core_1.ShapeDiverErrorType.Request; | ||
} | ||
exports.isGBRequestError = isGBRequestError; | ||
/** Type guard for a Geometry Backend SDK response error. */ | ||
function isGBResponseError(e) { | ||
return e instanceof Error && | ||
"errorType" in e && | ||
e.errorType === sdk_geometry_api_sdk_core_1.ShapeDiverErrorType.Response; | ||
} | ||
exports.isGBResponseError = isGBResponseError; | ||
/** | ||
@@ -17,0 +45,0 @@ * Sends the given request, handles retries for the HTTP status 429, and maps |
{ | ||
"name": "@shapediver/sdk.geometry-api-sdk-v2", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "SDK to communicate with the Geometry API version 2", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -73,2 +73,38 @@ <p align="center"> | ||
## Handling Errors | ||
The SDK provides type guards to distinguish between error types. | ||
``` | ||
import { | ||
isGBError, | ||
isGBGenericError, | ||
isGBRequestError, | ||
isGBResponseError, | ||
} from "@shapediver/sdk.geometry-api-sdk-v2" | ||
try { | ||
sdk.model.get("be5d4ce5-f76d-417d-8496-1f038e6f0cab") | ||
catch (e: any) { | ||
if (isGBRequestError(e)) { | ||
// e is a request error. | ||
// In this case, the request was made but no response was received. | ||
} | ||
if (isGBResponseError(e)) { | ||
// e is a response error. | ||
// In this case, the request was made and the server responded with a status code that falls | ||
// out of the range of 2xx. | ||
} | ||
if (isGBGenericError(e)) { | ||
// e is a generic error. | ||
// Generic errors are used for everything that is neither a request error nor a response error. | ||
} | ||
if (isGBError(e)) { | ||
// e is either a generic error, request error or response error. | ||
} | ||
} | ||
``` | ||
## Examples | ||
@@ -75,0 +111,0 @@ Some practical use cases, we will regularly extend the list: |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
145747
2053
122