convertFirebaseFunctionsException function

FirebaseFunctionsException convertFirebaseFunctionsException(
  1. JSObject exception, [
  2. StackTrace? stackTrace
])

Given a web error, a FirebaseFunctionsException is returned.

Implementation

FirebaseFunctionsException convertFirebaseFunctionsException(JSObject exception,
    [StackTrace? stackTrace]) {
  String originalCode =
      (exception.getProperty('code'.toJS)! as JSString).toDart;
  String code = originalCode.replaceFirst('functions/', '');
  String message = (exception.getProperty('message'.toJS)! as JSString)
      .toDart
      .replaceFirst('($originalCode)', '');

  return FirebaseFunctionsException(
    code: code,
    message: message,
    stackTrace: stackTrace,
    details: exception.getProperty('details'.toJS)?.dartify(),
  );
}