Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Nov 5, 2023
1 parent 5946e86 commit 3e6cbea
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,31 +333,31 @@ func (bl *FxBlockchain) handleAction(method string, action string, from peer.ID,
response, err := bl.callBlockchain(ctx, method, action, req)
if err != nil {
log.Error("failed to process action request: %v", err)
var apiError map[string]interface{}

// Assuming err is an error object that contains a JSON string with the error details.
// You would unmarshal it into the map.
if unmarshalErr := json.Unmarshal([]byte(err.Error()), &apiError); unmarshalErr != nil {
log.Error("failed to decode error details: %v", unmarshalErr)
http.Error(w, "", http.StatusInternalServerError)
return
}

apiErrorJSON, jsonErr := json.Marshal(apiError)
if jsonErr != nil {
log.Error("failed to encode error response: %v", jsonErr)
http.Error(w, "", http.StatusInternalServerError)
return
}

// Set the header and write the error JSON to the response writer.
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusBadRequest)
if _, writeErr := w.Write(apiErrorJSON); writeErr != nil {
log.Error("failed to write error response: %v", writeErr)
}
return
} else {
var apiError map[string]interface{}

// Assuming err is an error object that contains a JSON string with the error details.
// You would unmarshal it into the map.
if unmarshalErr := json.Unmarshal([]byte(err.Error()), &apiError); unmarshalErr != nil {
log.Error("failed to decode error details: %v", unmarshalErr)
http.Error(w, "", http.StatusInternalServerError)
return
}

apiErrorJSON, jsonErr := json.Marshal(apiError)
if jsonErr != nil {
log.Error("failed to encode error response: %v", jsonErr)
http.Error(w, "", http.StatusInternalServerError)
return
}

// Set the header and write the error JSON to the response writer.
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusBadRequest)
if _, writeErr := w.Write(apiErrorJSON); writeErr != nil {
log.Error("failed to write error response: %v", writeErr)
}
return
} else {
w.WriteHeader(http.StatusAccepted)
}

Expand Down

0 comments on commit 3e6cbea

Please sign in to comment.