Skip to content

Commit cbeecb6

Browse files
tniidiegobernardes
authored andcommitted
Add API error type
1 parent 1ce0d72 commit cbeecb6

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

ctrader.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package ctrader
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"reflect"
87

@@ -23,6 +22,16 @@ func (e undefinedProtobufResourceError[T]) Error() string {
2322
return fmt.Sprintf("undefined payload type '%d'", t.Elem())
2423
}
2524

25+
type ProtoOAError struct {
26+
ErrorCode string
27+
Description string
28+
MaintenanceEndTimestamp int64
29+
}
30+
31+
func (e ProtoOAError) Error() string {
32+
return fmt.Sprintf("%s: %s", e.ErrorCode, e.Description)
33+
}
34+
2635
// Command is a helper function used to send a request and receive a response.
2736
//
2837
// nolint ireturn
@@ -33,7 +42,7 @@ func Command[A, B proto.Message](ctx context.Context, c *Client, req A) (B, erro
3342
}
3443
switch v := resp.(type) {
3544
case *openapi.ProtoOAErrorRes:
36-
return *new(B), errors.New("failed authenticate the account")
45+
return *new(B), ProtoOAError{ErrorCode: v.GetErrorCode(), Description: v.GetDescription(), MaintenanceEndTimestamp: v.GetMaintenanceEndTimestamp()}
3746
case B:
3847
return v, nil
3948
default:

0 commit comments

Comments
 (0)