export function connectErrorDetails()

in packages/dubbo/src/dubbo-error.ts [209:240]


export function connectErrorDetails(
  error: ConnectError,
  typeOrRegistry: MessageType | IMessageTypeRegistry,
  ...moreTypes: MessageType[]
): AnyMessage[] {
  const types: MessageType[] =
    "typeName" in typeOrRegistry ? [typeOrRegistry, ...moreTypes] : [];
  const registry =
    "typeName" in typeOrRegistry ? createRegistry(...types) : typeOrRegistry;
  const details: AnyMessage[] = [];
  for (const data of error.details) {
    if (data instanceof Message) {
      if (registry.findMessage(data.getType().typeName)) {
        details.push(data);
      }
      continue;
    }
    const type = registry.findMessage(data.type);
    if (type) {
      try {
        details.push(type.fromBinary(data.value));
      } catch (_) {
        // We silently give up if we are unable to parse the detail, because
        // that appears to be the least worst behavior.
        // It is very unlikely that a user surrounds a catch body handling the
        // error with another try-catch statement, and we do not want to
        // recommend doing so.
      }
    }
  }
  return details;
}