@3dverse/api 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -836,6 +836,7 @@ function generateGuestToken({
836
836
  }
837
837
 
838
838
  // index.ts
839
+ import axiosRetry, { isNetworkError, isIdempotentRequestError } from "axios-retry";
839
840
  function setApiKey(apiKey) {
840
841
  axiosInstance.defaults.headers.common["api_key"] = apiKey;
841
842
  delete axiosInstance.defaults.headers.common["user_token"];
@@ -844,9 +845,6 @@ function setUserToken(userToken) {
844
845
  axiosInstance.defaults.headers.common["user_token"] = userToken;
845
846
  delete axiosInstance.defaults.headers.common["api_key"];
846
847
  }
847
- function setBaseUrl(url) {
848
- axiosInstance.defaults.baseURL = url;
849
- }
850
848
  var ServiceError = class extends Error {
851
849
  errorCode;
852
850
  httpCode;
@@ -876,6 +874,11 @@ var UnexpectedServiceError = class extends ServiceError {
876
874
  function installInterceptors() {
877
875
  const CLIENT_ERROR = 400;
878
876
  const INTERNAL_SERVER_ERROR = 500;
877
+ axiosRetry(axiosInstance, {
878
+ retries: 5,
879
+ retryDelay: axiosRetry.exponentialDelay,
880
+ retryCondition: shouldRetryRequest
881
+ });
879
882
  axiosInstance.interceptors.response.use(
880
883
  (successFulResponse) => {
881
884
  if (successFulResponse.config.responseType === "stream") {
@@ -893,14 +896,24 @@ function installInterceptors() {
893
896
  if (!errorData && axiosError.request.method === "HEAD" && status >= CLIENT_ERROR && status < INTERNAL_SERVER_ERROR) {
894
897
  return axiosError.response;
895
898
  }
896
- if (!errorData || !("error" in errorData)) {
899
+ if (!errorData || typeof errorData !== "object") {
897
900
  return Promise.reject(new UnexpectedServiceError(status, errorData));
898
901
  }
899
- const serviceError = errorData.error;
902
+ const serviceError = errorData;
900
903
  return Promise.reject(new ApiError(serviceError.errorCode, status, serviceError.message, serviceError));
901
904
  }
902
905
  );
903
906
  }
907
+ function shouldRetryRequest(error) {
908
+ const status = error.response?.status;
909
+ switch (status) {
910
+ case 403:
911
+ case 404:
912
+ return true;
913
+ default:
914
+ return isNetworkError(error) || isIdempotentRequestError(error);
915
+ }
916
+ }
904
917
  installInterceptors();
905
918
  export {
906
919
  ApiError,
@@ -972,7 +985,6 @@ export {
972
985
  setApiKey,
973
986
  setAssetThumbnail,
974
987
  setBaseURL,
975
- setBaseUrl,
976
988
  setUserToken,
977
989
  updateAssetDescription,
978
990
  updateEntity,