Skip to content

Commit 5571b71

Browse files
authored
Merge pull request #68 from cloudstruct/feat/accept-cbor-error
feat: return error cbor on request using accept header
2 parents bd6177d + d0aec33 commit 5571b71

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

internal/api/api.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,15 @@ func handleSubmitTx(c *gin.Context) {
227227
return nil
228228
},
229229
RejectTxFunc: func(reasonCbor []byte) error {
230-
var reason interface{}
231-
if err := cbor.Unmarshal(reasonCbor, &reason); err == nil {
232-
c.JSON(400, fmt.Sprintf("transaction rejected by node: %v (raw CBOR: %x)", reason, reasonCbor))
230+
if c.GetHeader("Accept") == "application/cbor" {
231+
c.Data(400, "application/cbor", reasonCbor)
233232
} else {
234-
c.JSON(400, fmt.Sprintf("transaction rejected by node, but the 'reason' data could not be parsed (raw CBOR: %x)", reasonCbor))
233+
var reason interface{}
234+
if err := cbor.Unmarshal(reasonCbor, &reason); err == nil {
235+
c.JSON(400, fmt.Sprintf("transaction rejected by node: %v (raw CBOR: %x)", reason, reasonCbor))
236+
} else {
237+
c.JSON(400, fmt.Sprintf("transaction rejected by node, but the 'reason' data could not be parsed (raw CBOR: %x)", reasonCbor))
238+
}
235239
}
236240
doneChan <- true
237241
// Increment custom metric

0 commit comments

Comments
 (0)