GeoLeaf Core API - v3.0.0
    Preparing search index...

    Function normalizeError

    • Coerces any caught value into a GeoLeafError.

      A catch binding is unknown — it may be an Error, a string, a plain object from a rejected fetch, or anything a third party threw. This flattens all of it to one shape so a handler can rely on .context and .toString().

      ⚠️ An existing Error is passed through and cast, not rebuilt: the result keeps the original prototype, so a TypeError stays a TypeError and gains no context. Only non-Error values are wrapped, with the original preserved under context.originalError.

      Parameters

      • error: unknown

        The caught value, of any shape.

      • defaultMessage: string = "An unknown error occurred"

        Message used when nothing usable can be extracted. Defaults to "An unknown error occurred".

      Returns GeoLeafError

      The value as a GeoLeafError.

      try {
      // code risqué
      } catch (rawError) {
      const err = GeoLeaf.Errors.normalizeError(rawError, "Unexpected error");
      GeoLeaf.Log.error(err.toString());
      }