Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit 7fad1bd

Browse files
committed
Merge pull request #32 from kaalita/master
CouchQuery stores error of the last request
2 parents 54ec21e + 0a233ae commit 7fad1bd

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

Couch/CouchQuery.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ typedef enum {
3838
BOOL _descending, _prefetch, _sequences;
3939
NSArray *_keys;
4040
NSUInteger _groupLevel;
41+
NSError* _error;
4142
}
4243

4344
/** The design document that contains this view. */
@@ -84,6 +85,9 @@ typedef enum {
8485

8586
@property BOOL sequences;
8687

88+
/** If non-nil, the error of the last execution of the query.
89+
If nil, the last exexution of the query was successful */
90+
@property (readonly,retain) NSError* error;
8791

8892
/** Starts an asynchronous query of the CouchDB view.
8993
When complete, the operation's resultObject will be the CouchQueryEnumerator. */

Couch/CouchQuery.m

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ - (id) initWithDatabase: (CouchDatabase*)db result: (id)result;
3232
@end
3333

3434

35+
@interface CouchQuery ()
36+
@property (readwrite,retain) NSError *error;
37+
@end
38+
3539

3640
@implementation CouchQuery
3741

@@ -63,13 +67,14 @@ - (void) dealloc
6367
[_startKeyDocID release];
6468
[_endKeyDocID release];
6569
[_keys release];
70+
[_error release];
6671
[super dealloc];
6772
}
6873

6974

7075
@synthesize limit=_limit, skip=_skip, descending=_descending, startKey=_startKey, endKey=_endKey,
7176
prefetch=_prefetch, keys=_keys, groupLevel=_groupLevel, startKeyDocID=_startKeyDocID,
72-
endKeyDocID=_endKeyDocID, stale=_stale, sequences=_sequences;
77+
endKeyDocID=_endKeyDocID, stale=_stale, sequences=_sequences, error=_error;
7378

7479

7580
- (CouchDesignDocument*) designDocument {
@@ -142,10 +147,11 @@ - (CouchQueryEnumerator*) rowsIfChanged {
142147

143148

144149
- (NSError*) operation: (RESTOperation*)op willCompleteWithError: (NSError*)error {
145-
error = [super operation: op willCompleteWithError: error];
146-
if (error)
147-
Warn(@"%@ failed with %@", self, error);
148-
if (!error && op.httpStatus == 200) {
150+
self.error = [super operation: op willCompleteWithError: error];
151+
if (_error)
152+
Warn(@"%@ failed with %@", self, _error);
153+
154+
if (!_error && op.httpStatus == 200) {
149155
NSDictionary* result = $castIf(NSDictionary, op.responseBody.fromJSON);
150156
NSArray* rows = $castIf(NSArray, [result objectForKey: @"rows"]);
151157
if (rows) {
@@ -154,10 +160,12 @@ - (NSError*) operation: (RESTOperation*)op willCompleteWithError: (NSError*)erro
154160
result: result] autorelease];
155161
} else {
156162
Warn(@"Couldn't parse rows from CouchDB view response");
157-
error = [RESTOperation errorWithHTTPStatus: 502 message: nil URL: self.URL];
163+
self.error = [RESTOperation errorWithHTTPStatus: 502
164+
message: @"Couldn't parse rows from CouchDB view response"
165+
URL: self.URL];
158166
}
159167
}
160-
return error;
168+
return _error;
161169
}
162170

163171

0 commit comments

Comments
 (0)