Skip to content

Commit ea49377

Browse files
authored
fix: handle lighter error properly (#115)
<!--- Provide a general summary of your changes in the Title above --> ## Description <!--- Describe your changes in detail --> ## Related Issue Or Context <!--- If suggesting a new feature or change, please discuss it in an issue first --> <!--- If fixing a bug, there should be an issue describing it with steps to reproduce --> <!--- Otherwise, describe context and motivation for change herre --> Closes: #<issue> ## How Has This Been Tested? Testing details. <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have ensured that all acceptance criteria (or expected behavior) from issue are met - [ ] I have updated the documentation locally and in docs. - [ ] I have added tests to cover my changes. - [ ] I have ensured that all the checks are passing and green, I've signed the CLA bot
1 parent 9b0865c commit ea49377

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

protocol/lighter/api.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ type LighterTx struct {
3636
Transfer *Transfer
3737
}
3838

39+
type LighterError struct {
40+
Code uint64 `json:"code"`
41+
Message string `json:"message"`
42+
}
43+
44+
func (e *LighterError) Error() error {
45+
return fmt.Errorf("lighter error: code %d, message: %s", e.Code, e.Message)
46+
}
47+
3948
func (tx *LighterTx) UnmarshalJSON(data []byte) error {
4049
type t LighterTx
4150
if err := json.Unmarshal(data, (*t)(tx)); err != nil {
@@ -85,7 +94,11 @@ func (a *LighterAPI) GetTx(hash string) (*LighterTx, error) {
8594

8695
s := new(LighterTx)
8796
if err := json.Unmarshal(body, s); err != nil {
88-
return nil, fmt.Errorf("failed to unmarshal response body: %s, with error: %w", string(body), err)
97+
e := new(LighterError)
98+
if err := json.Unmarshal(body, e); err != nil {
99+
return nil, fmt.Errorf("failed to unmarshal response body: %s, with error: %w", string(body), err)
100+
}
101+
return nil, e.Error()
89102
}
90103

91104
return s, nil

0 commit comments

Comments
 (0)