Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.
/ Blobfish Public archive

Easily handle errors and present them to the user in a nice way.

License

Notifications You must be signed in to change notification settings

ml-archive/Blobfish

Repository files navigation

This library has been deprecated and the repo has been archived.

The code is still here and you can still clone it, however the library will not receive any more updates or support.

  Blobfish

Easily handle errors and present them to the user in a nice way. Travis Carthage Compatible Plaform GitHub license

📦 Installation

Carthage

github "nodes-ios/Blobfish" ~> 1.0

Last versions compatible with lower Swift versions:

Swift 2.3
github "nodes-ios/Blobfish" == 0.2.0

Swift 2.2
github "nodes-ios/Blobfish" == 0.1.2

🔧 Setup

Blob & Blobbable

TODO: Add instructions

Alamofire Extension

In your AppDelegate's applicationDidFinishLaunching:launchOptions: function first do the basic setup of Blobfish:

Blobfish.AlamofireConfig.blobForTokenExpired = {
    let action = Blob.AlertAction(title: "Ok", handler: {
        // Your custom actions on token expired go here
    })
    return Blob(title: "Token Expired", 
    			style: .Alert(message: "Your token has expired. Please log in again.", actions: [action]))
}

Blobfish.AlamofireConfig.blobForUnknownError = { _, _ in
    let action = Blob.AlertAction(title: "Ok", handler: nil)
    return Blob(title: "Uknown Error", 
    			style: .Alert(message: "Unknown error happened, please try again.", actions: [action]))
}

Blobfish.AlamofireConfig.blobForConnectionError = { _ in
    return Blob(title: "Connection error, please try again.", style: .Overlay)
}

There is an extension to Alamofire Response to make it adhere to the Blobbable protocol, so handling errors in your callbacks should be a breeze.

func doSomeRequest(completion: Response<AnyObject, NSError> -> Void) { ... }
// ...
doSomeRequest(completion: { response in 
	switch response.result {
	case .Failure(_):
		// First, handle your custom error codes manually
		if response.response?.statusCode == 870 {
			// Your code to handle a custom error code
		} else {
			// Fallback to Blobfish
			Blobfish.sharedInstance.handle(response)
		}
	default: break
})

👥 Credits

Made with ❤️ at Nodes.

📄 License

Blobfish is available under the MIT license. See the LICENSE file for more info.