@@ -76,33 +76,39 @@ func handleCommitChain(ctx *web.Context) {
7676 if p , err := ioutil .ReadAll (ctx .Request .Body ); err != nil {
7777 wsLog .Error (err )
7878 ctx .WriteHeader (httpBad )
79+ ctx .Write ([]byte (err .Error ()))
7980 return
8081 } else {
8182 if err := json .Unmarshal (p , c ); err != nil {
8283 wsLog .Error (err )
8384 ctx .WriteHeader (httpBad )
85+ ctx .Write ([]byte (err .Error ()))
8486 return
8587 }
8688 }
8789
8890 commit := common .NewCommitChain ()
8991 if p , err := hex .DecodeString (c .CommitChainMsg ); err != nil {
9092 wsLog .Error (err )
93+ ctx .WriteHeader (httpBad )
94+ ctx .Write ([]byte (err .Error ()))
9195 return
9296 }else {
9397 if err := commit .UnmarshalBinary (p ); err != nil {
9498 wsLog .Error (err )
95- ctx .WriteHeader (httpBad )
99+ ctx .WriteHeader (httpBad )
100+ ctx .Write ([]byte (err .Error ()))
96101 return
97102 }
98103 }
99104 if err := factomapi .CommitChain (commit ); err != nil {
100105 wsLog .Error (err )
101106 ctx .WriteHeader (httpBad )
107+ ctx .Write ([]byte (err .Error ()))
102108 return
103109 }
104110
105- ctx .WriteHeader (httpOK )
111+ // ctx.WriteHeader(httpOK)
106112}
107113
108114func handleRevealChain (ctx * web.Context ) {
@@ -117,26 +123,36 @@ func handleCommitEntry(ctx *web.Context) {
117123 c := new (commitentry )
118124 if p , err := ioutil .ReadAll (ctx .Request .Body ); err != nil {
119125 wsLog .Error (err )
126+ ctx .WriteHeader (httpBad )
127+ ctx .Write ([]byte (err .Error ()))
120128 return
121129 } else {
122130 if err := json .Unmarshal (p , c ); err != nil {
123131 wsLog .Error (err )
132+ ctx .WriteHeader (httpBad )
133+ ctx .Write ([]byte (err .Error ()))
124134 return
125135 }
126136 }
127137
128138 commit := common .NewCommitEntry ()
129139 if p , err := hex .DecodeString (c .CommitEntryMsg ); err != nil {
130140 wsLog .Error (err )
141+ ctx .WriteHeader (httpBad )
142+ ctx .Write ([]byte (err .Error ()))
131143 return
132144 } else {
133145 if err := commit .UnmarshalBinary (p ); err != nil {
134146 wsLog .Error (err )
147+ ctx .WriteHeader (httpBad )
148+ ctx .Write ([]byte (err .Error ()))
135149 return
136150 }
137151 }
138152 if err := factomapi .CommitEntry (commit ); err != nil {
139153 wsLog .Error (err )
154+ ctx .WriteHeader (httpBad )
155+ ctx .Write ([]byte (err .Error ()))
140156 return
141157 }
142158
@@ -151,11 +167,13 @@ func handleRevealEntry(ctx *web.Context) {
151167 if p , err := ioutil .ReadAll (ctx .Request .Body ); err != nil {
152168 wsLog .Error (err )
153169 ctx .WriteHeader (httpBad )
170+ ctx .Write ([]byte (err .Error ()))
154171 return
155172 } else {
156173 if err := json .Unmarshal (p , e ); err != nil {
157174 wsLog .Error (err )
158175 ctx .WriteHeader (httpBad )
176+ ctx .Write ([]byte (err .Error ()))
159177 return
160178 }
161179 }
@@ -164,22 +182,25 @@ func handleRevealEntry(ctx *web.Context) {
164182 if p , err := hex .DecodeString (e .Entry ); err != nil {
165183 wsLog .Error (err )
166184 ctx .WriteHeader (httpBad )
185+ ctx .Write ([]byte (err .Error ()))
167186 return
168187 } else {
169188 if err := entry .UnmarshalBinary (p ); err != nil {
170189 wsLog .Error (err )
171190 ctx .WriteHeader (httpBad )
191+ ctx .Write ([]byte (err .Error ()))
172192 return
173193 }
174194 }
175195
176196 if err := factomapi .RevealEntry (entry ); err != nil {
177197 wsLog .Error (err )
178198 ctx .WriteHeader (httpBad )
199+ ctx .Write ([]byte (err .Error ()))
179200 return
180201 }
181202
182- ctx .WriteHeader (httpOK )
203+ // ctx.WriteHeader(httpOK)
183204}
184205
185206func handleDirectoryBlockHead (ctx * web.Context ) {
@@ -191,6 +212,7 @@ func handleDirectoryBlockHead(ctx *web.Context) {
191212 if block , err := factomapi .DBlockHead (); err != nil {
192213 wsLog .Error (err )
193214 ctx .WriteHeader (httpBad )
215+ ctx .Write ([]byte (err .Error ()))
194216 return
195217 } else {
196218 h .KeyMR = block .KeyMR .String ()
@@ -199,6 +221,7 @@ func handleDirectoryBlockHead(ctx *web.Context) {
199221 if p , err := json .Marshal (h ); err != nil {
200222 wsLog .Error (err )
201223 ctx .WriteHeader (httpBad )
224+ ctx .Write ([]byte (err .Error ()))
202225 return
203226 } else {
204227 ctx .Write (p )
@@ -226,6 +249,7 @@ func handleDirectoryBlock(ctx *web.Context, keymr string) {
226249 if block , err := factomapi .DBlockByKeyMR (keymr ); err != nil {
227250 wsLog .Error (err )
228251 ctx .WriteHeader (httpBad )
252+ ctx .Write ([]byte (err .Error ()))
229253 return
230254 } else {
231255 d .Header .PrevBlockKeyMR = block .Header .PrevKeyMR .String ()
@@ -242,12 +266,13 @@ func handleDirectoryBlock(ctx *web.Context, keymr string) {
242266 if p , err := json .Marshal (d ); err != nil {
243267 wsLog .Error (err )
244268 ctx .WriteHeader (httpBad )
269+ ctx .Write ([]byte (err .Error ()))
245270 return
246271 } else {
247272 ctx .Write (p )
248273 }
249274
250- ctx .WriteHeader (httpOK )
275+ // ctx.WriteHeader(httpOK)
251276}
252277
253278func handleEntryBlock (ctx * web.Context , keymr string ) {
@@ -269,6 +294,7 @@ func handleEntryBlock(ctx *web.Context, keymr string) {
269294 if block , err := factomapi .EBlockByKeyMR (keymr ); err != nil {
270295 wsLog .Error (err )
271296 ctx .WriteHeader (httpBad )
297+ ctx .Write ([]byte (err .Error ()))
272298 return
273299 } else {
274300 e .Header .BlockSequenceNumber = block .Header .EBHeight
@@ -285,12 +311,13 @@ func handleEntryBlock(ctx *web.Context, keymr string) {
285311 if p , err := json .Marshal (e ); err != nil {
286312 wsLog .Error (err )
287313 ctx .WriteHeader (httpBad )
314+ ctx .Write ([]byte (err .Error ()))
288315 return
289316 } else {
290317 ctx .Write (p )
291318 }
292319
293- ctx .WriteHeader (httpOK )
320+ // ctx.WriteHeader(httpOK)
294321}
295322
296323func handleEntry (ctx * web.Context , hash string ) {
@@ -303,6 +330,8 @@ func handleEntry(ctx *web.Context, hash string) {
303330 e := new (entry )
304331 if entry , err := factomapi .EntryByHash (hash ); err != nil {
305332 wsLog .Error (err )
333+ ctx .WriteHeader (httpBad )
334+ ctx .Write ([]byte (err .Error ()))
306335 return
307336 } else {
308337 e .ChainID = entry .ChainID .String ()
@@ -314,6 +343,8 @@ func handleEntry(ctx *web.Context, hash string) {
314343
315344 if p , err := json .Marshal (e ); err != nil {
316345 wsLog .Error (err )
346+ ctx .WriteHeader (httpBad )
347+ ctx .Write ([]byte (err .Error ()))
317348 return
318349 } else {
319350 ctx .Write (p )
@@ -327,15 +358,20 @@ func handleChainHead(ctx *web.Context, chainid string) {
327358 }
328359
329360 c := new (chead )
361+ fmt .Println ("DEBUG:" , c )
330362 if mr , err := factomapi .ChainHead (chainid ); err != nil {
331363 wsLog .Error (err )
364+ ctx .WriteHeader (httpBad )
365+ ctx .Write ([]byte (err .Error ()))
332366 return
333367 } else {
334368 c .EntryBlockKeyMR = mr .String ()
335369 }
336370
337371 if p , err := json .Marshal (c ); err != nil {
338372 wsLog .Error (err )
373+ ctx .WriteHeader (httpBad )
374+ ctx .Write ([]byte (err .Error ()))
339375 return
340376 } else {
341377 ctx .Write (p )
@@ -474,5 +510,4 @@ func handleGetFee(ctx *web.Context) {
474510 } else {
475511 ctx .Write (p )
476512 }
477-
478513}
0 commit comments