Memco

Function fromServiceError

  • Translate a gRPC failure into the error that says what happened.

    Returns rather than throws, so a caller can add context before raising.

    The mapping is by status code, with FAILED_PRECONDITION splitting further by the Memco-scoped google.rpc.ErrorInfo the call carries: a sunset becomes a MemcoSunsetError, and a refused placement the subclass its reason names. Any other precondition failure — an unknown reason included — stays a MemcoPreconditionFailedError, carrying whatever metadata the service attached. Any code with no entry becomes a MemcoInternalError, which is where an unrecognised status belongs — it is not something the caller did.

    Parameters

    • error: Partial<ServiceError>

      The rejection @grpc/grpc-js produced.

    Returns MemcoAPIError

    The typed error to raise.