GithubHelp home page GithubHelp logo

gwongz / rmerrors Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bithavoc/rmerrors

0.0 2.0 0.0 31 KB

Powerful Error Handling for iOS and OSX apps

License: MIT License

Ruby 2.06% Objective-C 97.94%

rmerrors's Introduction

RMErrors

Build Status

Powerful Error Handling for iOS and OSX apps

RMErrors describes instances NSError and returns friendly messages following rules set in a simple property list.

How it Works

The following example RMErrors.plist will setup RMErrors to:

  • NSError with domain NSURLErrorDomain and code between -1003 and -1009 will be described with friendly message the connection failed because the device is not connected to the internet.
  • NSError with domain NSURLErrorDomain and code -1001 will be described with friendly message The connection timed out, please make sure you're connected to the internet and try again.
  • NSError with domain NSURLErrorDomain and other codes not included by any of the previous rules will be described with friendly message Network issue
  • NSError with domain other than NSURLErrorDomain will be described with friendly message Oopss, something went wrong.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>(default)</key>
	<dict>
		<key>code</key>
		<integer>-1</integer>
		<key>friendlyMessage</key>
		<string>Oopss, something went wrong</string>
	</dict>
	<key>domains</key>
	<dict>
		<key>NSURLErrorDomain</key>
		<dict>
			<key>(default)</key>
			<dict>
				<key>transient</key>
				<true/>
				<key>friendlyMessage</key>
				<string>Network issue</string>
			</dict>
			<key>codes</key>
			<dict>
				<key>-1009..-1003</key>
				<dict>
					<key>transient</key>
					<true/>
					<key>friendlyMessage</key>
					<string>the connection failed because the device is not connected to the internet</string>
				</dict>
				<key>-1001</key>
				<dict>
					<key>transient</key>
					<true/>
					<key>friendlyMessage</key>
					<string>The connection timed out, please make sure you&apos;re connected to the internet and try again</string>
				</dict>
			</dict>
		</dict>
	</dict>
</dict>
</plist>

Usage

Install from Cocoapods

pod 'RMErrors'
$ pod install

Prepare configuration file

Create a new property list file in your project and make sure it's included in all the Xcode targets you intent to use from.

Initialize

RMErrors *errors = [[RMErrors alloc] init];
[errors loadPropertyList]; //loads from RMErrors.plist in main bundle.

Describing Errors

RMErrorDescription *description = [errors describe:[NSError errorWithDomain:@"com.foo.bar.oopsie" code:500 userInfo:nil]];
NSLog(@"Friendly Message: %@", description.friendlyMessage);

Outputs:

"Oopss, something went wrong"

Test & Enhance

$ cd Tests && pod install
$ open RMErrors.xcworkspace

rmerrors's People

Contributors

bithavoc avatar gwongz avatar guilleiguaran avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.