How to use the @bentley/bentleyjs-core.BentleyStatus.ERROR function in @bentley/bentleyjs-core

To help you get started, we’ve selected a few @bentley/bentleyjs-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imodeljs / imodeljs / core / clients / src / SettingsClient.ts View on Github external
} else {
          urlOptions = `/v1.0/Application/${this.applicationId}/Context/${projectId}${urlTerminator}`;
        }
      } else {
        urlOptions = `/v1.0/Application/${this.applicationId}${urlTerminator}`;
      }
    } else {
      if (projectId) {
        if (iModelId) {
          urlOptions = `/v1.0/Context/${projectId}/iModel/${iModelId}${urlTerminator}`;
        } else {
          urlOptions = `/v1.0/Context/${projectId}${urlTerminator}`;
        }
      } else {
        // settings must depend on at least one of Application and Project
        throw new BentleyError(BentleyStatus.ERROR, "Improperly specified setting");
      }
    }
    return urlOptions;
  }
github imodeljs / imodeljs / core / frontend / src / AccuDraw.ts View on Github external
fromPtP.vectorTo(inPtP, projectionVector).normalizeInPlace();
      } else {
        const rMatrix = vp.rotation;
        fromPtP = inPtP;
        rMatrix.getRow(2, projectionVector);
      }

      dotProduct = projectionVector.dotProduct(normalVectorP);

      if (Math.abs(dotProduct) < Constants.SMALL_DELTA)
        return BentleyStatus.ERROR; // PARALLEL;

      distance = (normalVectorP.dotProduct(pointOnPlaneP) - normalVectorP.dotProduct(fromPtP)) / dotProduct;

      if (isCamera && distance < Constants.SMALL_DELTA)
        return BentleyStatus.ERROR; // BEHIND_EYE_POINT;

      fromPtP.plusScaled(projectionVector, distance, outPtP);
    }

    return BentleyStatus.SUCCESS;
  }
github imodeljs / imodeljs / core / clients / src / projectshare / ProjectShareClient.ts View on Github external
public async readFile(requestContext: AuthorizedClientRequestContext, file: ProjectShareFile, maxByteCount?: number): Promise {
    requestContext.enter();
    if (typeof window === "undefined")
      throw new BentleyError(BentleyStatus.ERROR, "Method meant only for browser use. For node.js use call readFileNodeJs()", Logger.logError, loggerCategory);
    if (!file.accessUrl)
      throw new BentleyError(BentleyStatus.ERROR, "Supplied file must have an accessUrl", Logger.logError, loggerCategory, () => ({ ...file }));

    const requestInit = maxByteCount === undefined ? undefined : {
      headers: {
        Range: `bytes=0-${maxByteCount}`,
      },
    };
    const response: Response = await fetch(file.accessUrl, requestInit);
    if (!response.body)
      throw new BentleyError(BentleyStatus.ERROR, "Empty file", Logger.logError, loggerCategory, () => ({ ...file }));

    const reader = response.body.getReader();

    // Determine size of stream from "Content-Length" in headers, or meta data on file
    const contentLengthStr = response.headers.get("Content-Length");
    const totalByteCount = contentLengthStr ? +contentLengthStr : file.size;
    if (totalByteCount === undefined)
      throw new BentleyError(BentleyStatus.ERROR, "Could not determine size of file", Logger.logError, loggerCategory, () => ({ ...file }));

    const copyByteCount = maxByteCount ? Math.min(totalByteCount, maxByteCount) : totalByteCount;
    const retArray = new Uint8Array(copyByteCount);
    let offset = 0;
    while (offset < copyByteCount) {
      const { done, value: chunk } = await reader.read();
      if (done)
        break;
github imodeljs / imodeljs / core / frontend / src / render / webgl / System.ts View on Github external
public static create(optionsIn?: RenderSystem.Options): System {
    const options: RenderSystem.Options = undefined !== optionsIn ? optionsIn : {};
    const canvas = document.createElement("canvas") as HTMLCanvasElement;
    if (null === canvas)
      throw new IModelError(BentleyStatus.ERROR, "Failed to obtain HTMLCanvasElement");

    const context = System.createContext(canvas);
    if (undefined === context) {
      throw new IModelError(BentleyStatus.ERROR, "Failed to obtain WebGL context");
    }

    const capabilities = Capabilities.create(context, options.disabledExtensions);
    if (undefined === capabilities)
      throw new IModelError(BentleyStatus.ERROR, "Failed to initialize rendering capabilities");

    // set actual gl state to match desired state defaults
    context.depthFunc(GL.DepthFunc.Default);  // LessOrEqual

    if (!capabilities.supportsShadowMaps)
      options.displaySolarShadows = false;
    if (!capabilities.supportsFragDepth)
github imodeljs / imodeljs / core / clients-backend / src / oidc / OidcAgentClientV1.ts View on Github external
public async refreshToken(requestContext: ClientRequestContext, jwt: AccessToken): Promise {
    requestContext.enter();

    // Refresh 1 minute before expiry
    const expiresAt = jwt.getExpiresAt();
    if (!expiresAt)
      throw new BentleyError(BentleyStatus.ERROR, "Invalid JWT passed to refresh");
    if ((expiresAt.getTime() - Date.now()) > 1 * 60 * 1000)
      return jwt;

    return this.getToken(requestContext);
  }
}
github imodeljs / imodeljs / core / common / src / rpc / mobile / MobileRpcManager.ts View on Github external
private static getArgs(): any {
    if (typeof window === "undefined") {
      return {};
    }

    const queryArgs: any = {};
    const matches = window.location.hash.match(/([^#=&]+)(=([^&]*))?/g);
    if (matches) {
      for (const comp of matches) {
        const array = comp.split("=");
        if (array.length === 2) {
          const key = decodeURIComponent(array[0]);
          const val = decodeURIComponent(array[1]);
          queryArgs[key] = val;
        } else {
          throw new IModelError(BentleyStatus.ERROR, "Unexpected parameters");
        }
      }
    }
    return queryArgs;
  }
  private static getMobilePlatform(): RpcMobilePlatform {
github imodeljs / imodeljs / core / frontend / src / AccuDraw.ts View on Github external
break;

      case ItemField.Y_Item:
        if (BentleyStatus.SUCCESS !== this.stringToUORs([this.delta.y], input))
          return BentleyStatus.ERROR;

        this._yIsExplicit = (input[0] === "+" || input[0] === "-");
        if (!this._yIsExplicit) {
          if (this.smartKeyin && this.isActive && this._yIsNegative === (this.delta.y >= 0.0))
            this.delta.y = -this.delta.y;
        }
        break;

      case ItemField.Z_Item:
        if (BentleyStatus.SUCCESS !== this.stringToUORs([this.delta.z], input))
          return BentleyStatus.ERROR;
        break;
    }

    return BentleyStatus.SUCCESS;
  }
github imodeljs / imodeljs / core / frontend / src / render / webgl / GLTimer.ts View on Github external
public set resultsCallback(callback: GLTimerResultCallback | undefined) {
    if (this._queryStack.length !== 0)
      throw new IModelError(BentleyStatus.ERROR, "Do not set resultsCallback when a frame is already being drawn");

    this._resultsCallback = callback;
  }
github imodeljs / imodeljs / core / clients-backend / src / oidc / OidcDelegationClient.ts View on Github external
public async getSamlFromJwt(requestContext: ClientRequestContext, jwt: AccessToken): Promise {
    requestContext.enter();

    const grantType = "urn:ietf:params:oauth:grant-type:jwt-bearer";
    const params: GrantParams = {
      grant_type: grantType,
      scope: this._configuration.scope,
      assertion: jwt.toTokenString(IncludePrefix.No),
    };

    const client = await this.getClient(requestContext);
    const tokenSet: TokenSet = await client.grant(params);

    const samlToken = AccessToken.fromSamlTokenString(tokenSet.access_token, IncludePrefix.No);
    if (!samlToken)
      throw new BentleyError(BentleyStatus.ERROR, `Could not convert jwt to accessToken`);
    return samlToken;
  }