Skip to content

Commit 3696fe2

Browse files
authored
fix: typo (#5166)
Signed-off-by: LesCyber <[email protected]>
1 parent 239abb1 commit 3696fe2

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,12 @@ func (dbclient *couchDatabase) createDatabaseIfNotExist() error {
239239

240240
dbInfo, couchDBReturn, err := dbclient.getDatabaseInfo()
241241
if err != nil {
242-
if couchDBReturn == nil || couchDBReturn.StatusCode != 404 {
242+
if couchDBReturn == nil || couchDBReturn.StatusCode != http.StatusNotFound {
243243
return err
244244
}
245245
}
246246

247-
if dbInfo == nil || couchDBReturn.StatusCode == 404 {
247+
if dbInfo == nil || couchDBReturn.StatusCode == http.StatusNotFound {
248248
couchdbLogger.Debugf("[%s] Database does not exist.", dbclient.dbName)
249249

250250
connectURL, err := url.Parse(dbclient.couchInstance.url())
@@ -265,7 +265,7 @@ func (dbclient *couchDatabase) createDatabaseIfNotExist() error {
265265
// returned due to a timeout or race condition.
266266
// Do a final check to see if the database really got created.
267267
dbInfo, couchDBReturn, dbInfoErr := dbclient.getDatabaseInfo()
268-
if dbInfoErr != nil || dbInfo == nil || couchDBReturn.StatusCode == 404 {
268+
if dbInfoErr != nil || dbInfo == nil || couchDBReturn.StatusCode == http.StatusNotFound {
269269
return err
270270
}
271271
}
@@ -494,7 +494,7 @@ func (dbclient *couchDatabase) dropDatabase() error {
494494

495495
resp, couchdbReturn, err := dbclient.handleRequest(http.MethodDelete, "DropDatabase", connectURL, nil, "", "", maxRetries, true, nil)
496496
defer closeResponseBody(resp)
497-
if couchdbReturn != nil && couchdbReturn.StatusCode == 404 {
497+
if couchdbReturn != nil && couchdbReturn.StatusCode == http.StatusNotFound {
498498
couchdbLogger.Debugf("[%s] Exiting DropDatabase(), database does not exist", dbclient.dbName)
499499
return nil
500500
}
@@ -721,7 +721,7 @@ func (dbclient *couchDatabase) readDoc(id string) (*couchDoc, string, error) {
721721

722722
resp, couchDBReturn, err := dbclient.handleRequest(http.MethodGet, "ReadDoc", readURL, nil, "", "", maxRetries, true, &query, id)
723723
if err != nil {
724-
if couchDBReturn != nil && couchDBReturn.StatusCode == 404 {
724+
if couchDBReturn != nil && couchDBReturn.StatusCode == http.StatusNotFound {
725725
couchdbLogger.Debugf("[%s] Document not found (404), returning nil value instead of 404 error", dbclient.dbName)
726726
// non-existent document should return nil value instead of a 404 error
727727
// for details see https://github.com/hyperledger-archives/fabric/issues/936
@@ -972,7 +972,7 @@ func (dbclient *couchDatabase) deleteDoc(id, rev string) error {
972972
resp, couchDBReturn, err := dbclient.handleRequestWithRevisionRetry(id, http.MethodDelete, dbName, "DeleteDoc",
973973
deleteURL, nil, "", "", maxRetries, true, nil)
974974
if err != nil {
975-
if couchDBReturn != nil && couchDBReturn.StatusCode == 404 {
975+
if couchDBReturn != nil && couchDBReturn.StatusCode == http.StatusNotFound {
976976
couchdbLogger.Debugf("[%s] Document not found (404), returning nil value instead of 404 error", dbclient.dbName)
977977
// non-existent document should return nil value instead of a 404 error
978978
// for details see https://github.com/hyperledger-archives/fabric/issues/936
@@ -1525,7 +1525,7 @@ func (dbclient *couchDatabase) handleRequestWithRevisionRetry(id, method, dbName
15251525

15261526
// If there was a 409 conflict error during the save/delete, log it and retry it.
15271527
// Otherwise, break out of the retry loop
1528-
if couchDBReturn != nil && couchDBReturn.StatusCode == 409 {
1528+
if couchDBReturn != nil && couchDBReturn.StatusCode == http.StatusConflict {
15291529
couchdbLogger.Warningf("CouchDB document revision conflict detected, retrying. Attempt:%v", attempts+1)
15301530
revisionConflictDetected = true
15311531
} else {
@@ -1641,9 +1641,9 @@ func (couchInstance *couchInstance) handleRequest(ctx context.Context, method, d
16411641
}
16421642

16431643
// 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 {
16451645
// if this is an error, then populate the couchDBReturn
1646-
if resp.StatusCode >= 400 {
1646+
if resp.StatusCode >= http.StatusBadRequest {
16471647
// Read the response body and close it for next attempt
16481648
jsonError, err := io.ReadAll(resp.Body)
16491649
if err != nil {
@@ -1727,7 +1727,7 @@ func (couchInstance *couchInstance) handleRequest(ctx context.Context, method, d
17271727
// check to see if the status code from couchdb is 400 or higher
17281728
// response codes 4XX and 500 will be treated as errors -
17291729
// 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 {
17311731

17321732
// if the status code is 400 or greater, log and return an error
17331733
couchdbLogger.Debugf("Error handling CouchDB request. Error:%s, Status Code:%v, Reason:%s",

core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdbutil.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func createCouchInstance(config *ledger.CouchDBConfig, metricsProvider metrics.P
9090
}
9191

9292
// return an error if the http return value is not 200
93-
if retVal.StatusCode != 200 {
93+
if retVal.StatusCode != http.StatusOK {
9494
return nil, errors.Errorf("CouchDB connection error, expecting return code of 200, received %v", retVal.StatusCode)
9595
}
9696

core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"bytes"
1111
"context"
1212
"encoding/json"
13+
"net/http"
1314
"sort"
1415
"sync"
1516

@@ -203,7 +204,7 @@ func (provider *VersionedDBProvider) Drop(dbName string) error {
203204
metadataDBName := constructMetadataDBName(dbName)
204205
couchDBDatabase := couchDatabase{couchInstance: provider.couchInstance, dbName: metadataDBName}
205206
_, couchDBReturn, err := couchDBDatabase.getDatabaseInfo()
206-
if couchDBReturn != nil && couchDBReturn.StatusCode == 404 {
207+
if couchDBReturn != nil && couchDBReturn.StatusCode == http.StatusNotFound {
207208
// db does not exist
208209
return nil
209210
}

0 commit comments

Comments
 (0)