jens@7
|
1 |
//
|
jens@7
|
2 |
// URLUtils.m
|
jens@11
|
3 |
// MYUtilities
|
jens@7
|
4 |
//
|
jens@7
|
5 |
// Created by Jens Alfke on 4/28/08.
|
jens@11
|
6 |
// Copyright 2008 Jens Alfke. All rights reserved.
|
jens@7
|
7 |
//
|
jens@7
|
8 |
|
jens@7
|
9 |
#import "URLUtils.h"
|
jens@7
|
10 |
|
jens@7
|
11 |
|
jens@7
|
12 |
@implementation NSHTTPURLResponse (MYUtilities)
|
jens@7
|
13 |
|
jens@7
|
14 |
|
jens@7
|
15 |
- (NSError*) HTTPError
|
jens@7
|
16 |
{
|
jens@7
|
17 |
// HTTP status >= 300 is considered an error:
|
jens@7
|
18 |
int status = self.statusCode;
|
jens@7
|
19 |
if( status >= 300 ) {
|
jens@7
|
20 |
NSString *reason = NSLocalizedStringFromTable( @"HTTP_ERROR_MESSAGE",@"UKCrashReporter",@"");
|
jens@7
|
21 |
reason = [NSHTTPURLResponse localizedStringForStatusCode: status];
|
jens@7
|
22 |
NSDictionary *info = $dict({NSLocalizedFailureReasonErrorKey,reason});
|
jens@7
|
23 |
return [NSError errorWithDomain: MyHTTPErrorDomain code: status userInfo: info];
|
jens@7
|
24 |
} else
|
jens@7
|
25 |
return nil;
|
jens@7
|
26 |
}
|
jens@7
|
27 |
|
jens@7
|
28 |
|
jens@7
|
29 |
NSString* const MyHTTPErrorDomain = @"HTTP";
|
jens@7
|
30 |
|
jens@7
|
31 |
|
jens@7
|
32 |
@end
|
jens@11
|
33 |
|
jens@11
|
34 |
|
jens@11
|
35 |
/*
|
jens@11
|
36 |
Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
|
jens@11
|
37 |
|
jens@11
|
38 |
Redistribution and use in source and binary forms, with or without modification, are permitted
|
jens@11
|
39 |
provided that the following conditions are met:
|
jens@11
|
40 |
|
jens@11
|
41 |
* Redistributions of source code must retain the above copyright notice, this list of conditions
|
jens@11
|
42 |
and the following disclaimer.
|
jens@11
|
43 |
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
|
jens@11
|
44 |
and the following disclaimer in the documentation and/or other materials provided with the
|
jens@11
|
45 |
distribution.
|
jens@11
|
46 |
|
jens@11
|
47 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
jens@11
|
48 |
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
jens@11
|
49 |
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
|
jens@11
|
50 |
BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
jens@11
|
51 |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
jens@11
|
52 |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
jens@11
|
53 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
jens@11
|
54 |
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
jens@11
|
55 |
*/
|