@@ -239,12 +239,12 @@ func (dbclient *couchDatabase) createDatabaseIfNotExist() error {
239
239
240
240
dbInfo , couchDBReturn , err := dbclient .getDatabaseInfo ()
241
241
if err != nil {
242
- if couchDBReturn == nil || couchDBReturn .StatusCode != 404 {
242
+ if couchDBReturn == nil || couchDBReturn .StatusCode != http . StatusNotFound {
243
243
return err
244
244
}
245
245
}
246
246
247
- if dbInfo == nil || couchDBReturn .StatusCode == 404 {
247
+ if dbInfo == nil || couchDBReturn .StatusCode == http . StatusNotFound {
248
248
couchdbLogger .Debugf ("[%s] Database does not exist." , dbclient .dbName )
249
249
250
250
connectURL , err := url .Parse (dbclient .couchInstance .url ())
@@ -265,7 +265,7 @@ func (dbclient *couchDatabase) createDatabaseIfNotExist() error {
265
265
// returned due to a timeout or race condition.
266
266
// Do a final check to see if the database really got created.
267
267
dbInfo , couchDBReturn , dbInfoErr := dbclient .getDatabaseInfo ()
268
- if dbInfoErr != nil || dbInfo == nil || couchDBReturn .StatusCode == 404 {
268
+ if dbInfoErr != nil || dbInfo == nil || couchDBReturn .StatusCode == http . StatusNotFound {
269
269
return err
270
270
}
271
271
}
@@ -494,7 +494,7 @@ func (dbclient *couchDatabase) dropDatabase() error {
494
494
495
495
resp , couchdbReturn , err := dbclient .handleRequest (http .MethodDelete , "DropDatabase" , connectURL , nil , "" , "" , maxRetries , true , nil )
496
496
defer closeResponseBody (resp )
497
- if couchdbReturn != nil && couchdbReturn .StatusCode == 404 {
497
+ if couchdbReturn != nil && couchdbReturn .StatusCode == http . StatusNotFound {
498
498
couchdbLogger .Debugf ("[%s] Exiting DropDatabase(), database does not exist" , dbclient .dbName )
499
499
return nil
500
500
}
@@ -721,7 +721,7 @@ func (dbclient *couchDatabase) readDoc(id string) (*couchDoc, string, error) {
721
721
722
722
resp , couchDBReturn , err := dbclient .handleRequest (http .MethodGet , "ReadDoc" , readURL , nil , "" , "" , maxRetries , true , & query , id )
723
723
if err != nil {
724
- if couchDBReturn != nil && couchDBReturn .StatusCode == 404 {
724
+ if couchDBReturn != nil && couchDBReturn .StatusCode == http . StatusNotFound {
725
725
couchdbLogger .Debugf ("[%s] Document not found (404), returning nil value instead of 404 error" , dbclient .dbName )
726
726
// non-existent document should return nil value instead of a 404 error
727
727
// for details see https://github.com/hyperledger-archives/fabric/issues/936
@@ -972,7 +972,7 @@ func (dbclient *couchDatabase) deleteDoc(id, rev string) error {
972
972
resp , couchDBReturn , err := dbclient .handleRequestWithRevisionRetry (id , http .MethodDelete , dbName , "DeleteDoc" ,
973
973
deleteURL , nil , "" , "" , maxRetries , true , nil )
974
974
if err != nil {
975
- if couchDBReturn != nil && couchDBReturn .StatusCode == 404 {
975
+ if couchDBReturn != nil && couchDBReturn .StatusCode == http . StatusNotFound {
976
976
couchdbLogger .Debugf ("[%s] Document not found (404), returning nil value instead of 404 error" , dbclient .dbName )
977
977
// non-existent document should return nil value instead of a 404 error
978
978
// for details see https://github.com/hyperledger-archives/fabric/issues/936
@@ -1525,7 +1525,7 @@ func (dbclient *couchDatabase) handleRequestWithRevisionRetry(id, method, dbName
1525
1525
1526
1526
// If there was a 409 conflict error during the save/delete, log it and retry it.
1527
1527
// Otherwise, break out of the retry loop
1528
- if couchDBReturn != nil && couchDBReturn .StatusCode == 409 {
1528
+ if couchDBReturn != nil && couchDBReturn .StatusCode == http . StatusConflict {
1529
1529
couchdbLogger .Warningf ("CouchDB document revision conflict detected, retrying. Attempt:%v" , attempts + 1 )
1530
1530
revisionConflictDetected = true
1531
1531
} else {
@@ -1641,9 +1641,9 @@ func (couchInstance *couchInstance) handleRequest(ctx context.Context, method, d
1641
1641
}
1642
1642
1643
1643
// if there is no golang http error and no CouchDB 500 error, then drop out of the retry
1644
- if errResp == nil && resp != nil && resp .StatusCode < 500 {
1644
+ if errResp == nil && resp != nil && resp .StatusCode < http . StatusInternalServerError {
1645
1645
// if this is an error, then populate the couchDBReturn
1646
- if resp .StatusCode >= 400 {
1646
+ if resp .StatusCode >= http . StatusBadRequest {
1647
1647
// Read the response body and close it for next attempt
1648
1648
jsonError , err := io .ReadAll (resp .Body )
1649
1649
if err != nil {
@@ -1727,7 +1727,7 @@ func (couchInstance *couchInstance) handleRequest(ctx context.Context, method, d
1727
1727
// check to see if the status code from couchdb is 400 or higher
1728
1728
// response codes 4XX and 500 will be treated as errors -
1729
1729
// golang error will be created from the couchDBReturn contents and both will be returned
1730
- if resp .StatusCode >= 400 {
1730
+ if resp .StatusCode >= http . StatusBadRequest {
1731
1731
1732
1732
// if the status code is 400 or greater, log and return an error
1733
1733
couchdbLogger .Debugf ("Error handling CouchDB request. Error:%s, Status Code:%v, Reason:%s" ,
0 commit comments