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

Commit

Permalink
CouchQuery: Added error property for retrieving the last error of the…
Browse files Browse the repository at this point in the history
… request
  • Loading branch information
kaalita committed Jul 2, 2012
1 parent 54ec21e commit 711b1c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Couch/CouchQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef enum {
BOOL _descending, _prefetch, _sequences;
NSArray *_keys;
NSUInteger _groupLevel;
NSError* _error;
}

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

@property BOOL sequences;

/** If non-nil, the error of the last execution of the query
If nil, the last exexution of the query was successful */
@property (readonly) NSError* error;

/** Starts an asynchronous query of the CouchDB view.
When complete, the operation's resultObject will be the CouchQueryEnumerator. */
Expand Down
12 changes: 9 additions & 3 deletions Couch/CouchQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ - (void) dealloc
[_startKeyDocID release];
[_endKeyDocID release];
[_keys release];
[_error release];
[super dealloc];
}


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


- (CouchDesignDocument*) designDocument {
Expand Down Expand Up @@ -143,8 +144,10 @@ - (CouchQueryEnumerator*) rowsIfChanged {

- (NSError*) operation: (RESTOperation*)op willCompleteWithError: (NSError*)error {
error = [super operation: op willCompleteWithError: error];
if (error)
if (error) {
Warn(@"%@ failed with %@", self, error);
_error = [error retain];
}
if (!error && op.httpStatus == 200) {
NSDictionary* result = $castIf(NSDictionary, op.responseBody.fromJSON);
NSArray* rows = $castIf(NSArray, [result objectForKey: @"rows"]);
Expand All @@ -154,7 +157,10 @@ - (NSError*) operation: (RESTOperation*)op willCompleteWithError: (NSError*)erro
result: result] autorelease];
} else {
Warn(@"Couldn't parse rows from CouchDB view response");
error = [RESTOperation errorWithHTTPStatus: 502 message: nil URL: self.URL];
error = [RESTOperation errorWithHTTPStatus: 502
message: @"Couldn't parse rows from CouchDB view response"
URL: self.URL];
_error = [error retain];
}
}
return error;
Expand Down

0 comments on commit 711b1c9

Please sign in to comment.