void validate ( HttpResponse response ) throws IOException { final int code = response . getStatusLine ( ) . getStatusCode ( ) ; if ( code == 200 || code == 201 || code == 202 ) { // success (ok | created | accepted) return ; } String reason = response . getStatusLine ( ) . getReasonPhrase ( ) ; switch ( code ) { case HttpStatus . SC_NOT_FOUND : { throw new NoDocumentException ( reason ) ; } case HttpStatus . SC_CONFLICT : { throw new DocumentConflictException ( reason ) ; } default : { // other errors: 400 | 401 | 500 etc. throw new CouchDbException ( reason += EntityUtils . toString ( response . getEntity ( ) ) ) ; } } }
Validates a HTTP response ; on error cases logs status and throws relevant exceptions .