From 887f8726d8c35c3220a4eec262a730145f722ab5 Mon Sep 17 00:00:00 2001 From: ehsan shariati Date: Sun, 5 Nov 2023 01:40:39 -0500 Subject: [PATCH] Update blockchain.go --- blockchain/blockchain.go | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index 61838b4e..2c47b384 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -332,30 +332,9 @@ func (bl *FxBlockchain) handleAction(method string, action string, from peer.ID, defer cancel() response, err := bl.callBlockchain(ctx, method, action, req) if err != nil { + errorMessage := err.Error() + http.Error(w, errorMessage, http.StatusBadRequest) 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 { w.WriteHeader(http.StatusAccepted)