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

CouchQuery stores error of the last request #32

Merged
merged 2 commits into from
Jul 7, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,retain) NSError* error;

/** Starts an asynchronous query of the CouchDB view.
When complete, the operation's resultObject will be the CouchQueryEnumerator. */
Expand Down
22 changes: 15 additions & 7 deletions Couch/CouchQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ - (id) initWithDatabase: (CouchDatabase*)db result: (id)result;
@end


@interface CouchQuery ()
@property (readwrite,retain) NSError *error;
@end


@implementation CouchQuery

Expand Down Expand Up @@ -63,13 +67,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 @@ -142,10 +147,11 @@ - (CouchQueryEnumerator*) rowsIfChanged {


- (NSError*) operation: (RESTOperation*)op willCompleteWithError: (NSError*)error {
error = [super operation: op willCompleteWithError: error];
if (error)
Warn(@"%@ failed with %@", self, error);
if (!error && op.httpStatus == 200) {
self.error = [super operation: op willCompleteWithError: error];
if (_error)
Warn(@"%@ failed with %@", self, _error);

if (!_error && op.httpStatus == 200) {
NSDictionary* result = $castIf(NSDictionary, op.responseBody.fromJSON);
NSArray* rows = $castIf(NSArray, [result objectForKey: @"rows"]);
if (rows) {
Expand All @@ -154,10 +160,12 @@ - (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];
self.error = [RESTOperation errorWithHTTPStatus: 502
message: @"Couldn't parse rows from CouchDB view response"
URL: self.URL];
}
}
return error;
return _error;
}


Expand Down