Skip to content

Commit

Permalink
Merge pull request #7 from mz2/master
Browse files Browse the repository at this point in the history
Adds an error domain and codes for some error scenarios
  • Loading branch information
newzealandpaul committed Oct 5, 2014
2 parents b02bcfe + 75df3a1 commit f759059
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 9 additions & 0 deletions KBWebArchiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>

extern NSString *const KBWebArchiverErrorDomain;

typedef NS_ENUM(NSUInteger, KBWebArchiverErrorCode) {
KBWebArchiverErrorCodeUnknown = 0,
KBWebArchiverErrorCodeInvalidURL = 1,
KBWebArchiverErrorCodeLoadFailed = 2,
KBWebArchiverErrorCodeArchiveCreationFailed = 3
};

@interface KBWebArchiver : NSObject
{
NSURL *_URL;
Expand Down
14 changes: 11 additions & 3 deletions KBWebArchiver.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#import "NSURL+ValidityChecking.h"


NSString *const KBWebArchiverErrorDomain = @"KBWebArchiverErrorDomain";

@interface KBWebArchiver (Private)
- (void)getWebPage;
@end
Expand Down Expand Up @@ -153,7 +155,9 @@ - (void)getWebPage
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
userInfo[NSLocalizedDescriptionKey] = NSLocalizedString(@"Invalid URL", @"");
userInfo[NSLocalizedRecoverySuggestionErrorKey] = NSLocalizedString(@"The URL was invalid and so could not be converted to a web archive.",nil);
_archiveInformation[@"Error"] = [NSError errorWithDomain:@"" code:0 userInfo:userInfo];
_archiveInformation[@"Error"] = [NSError errorWithDomain:KBWebArchiverErrorDomain
code:KBWebArchiverErrorCodeInvalidURL
userInfo:userInfo];

return;
}
Expand Down Expand Up @@ -249,7 +253,9 @@ - (void)getWebPage
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
userInfo[NSLocalizedDescriptionKey] = NSLocalizedString(@"Web Page Failed to Load", @"");
userInfo[NSLocalizedRecoverySuggestionErrorKey] = NSLocalizedString(@"The web page at the given URL failed to load and so could not be converted to a WebArchive.",nil);
_archiveInformation[@"Error"] = [NSError errorWithDomain:@"" code:0 userInfo:userInfo];
_archiveInformation[@"Error"] = [NSError errorWithDomain:KBWebArchiverErrorDomain
code:KBWebArchiverErrorCodeLoadFailed
userInfo:userInfo];
}

return;
Expand All @@ -276,7 +282,9 @@ - (void)getWebPage
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
userInfo[NSLocalizedDescriptionKey] = NSLocalizedString(@"Web Archive Creation Failed", @"");
userInfo[NSLocalizedRecoverySuggestionErrorKey] = NSLocalizedString(@"A web archive could not be created from the page at the given URL.",nil);
_archiveInformation[@"Error"] = [NSError errorWithDomain:@"" code:0 userInfo:userInfo];
_archiveInformation[@"Error"] = [NSError errorWithDomain:KBWebArchiverErrorDomain
code:KBWebArchiverErrorCodeArchiveCreationFailed
userInfo:userInfo];
}


Expand Down

0 comments on commit f759059

Please sign in to comment.