Skip to content

Add custom error mapping #27

Closed
Closed
@Sherlouk

Description

@Sherlouk

Problem Statement

You already have a handful of built-in error mappings for common Apple frameworks like URLSession, FileManager, and CoreData. Functions like mapToThrowable, userFriendlyFoundationMessage and others.

These global handlers are called within userFriendlyMessage to try and map to the best possible error message. Awesome.

What would be nice is if I was able to provide my own "error matchers" to map an Error to a Throwable.

The purpose of this is to:

  1. Enable an ecosystem of third-party libraries that provide extensions to this primary product. Providing mappings to errors thrown by many third parties, no matter what they be, and without requiring adoption upstream.
  2. Adds a centralised way to map error messages within a product, which can be useful to ease in initial onboarding, and in cases where you want to provide backend messages.

Suggested Solution

protocol ThrowableMappingProvider {
  func mapToThrowable(error: Error) -> Throwable? // Where `nil` is unhandled, and falls to the next.
}

ErrorKitMapper.register(MyMappingProvider()) // this would store as an array, first registered gets checked first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions