@@ -40,33 +40,6 @@ const (
40
40
StatusUnknown Status = ""
41
41
)
42
42
43
- // UnpackError returns error with possibility to access RawMessage when
44
- // connection failed to unpack message
45
- type UnpackError struct {
46
- Err error
47
- RawMessage []byte
48
- }
49
-
50
- func (e * UnpackError ) Error () string {
51
- return e .Err .Error ()
52
- }
53
-
54
- func (e * UnpackError ) Unwrap () error {
55
- return e .Err
56
- }
57
-
58
- type PackError struct {
59
- Err error
60
- }
61
-
62
- func (e * PackError ) Error () string {
63
- return e .Err .Error ()
64
- }
65
-
66
- func (e * PackError ) Unwrap () error {
67
- return e .Err
68
- }
69
-
70
43
// Connection represents an ISO 8583 Connection. Connection may be used
71
44
// by multiple goroutines simultaneously.
72
45
type Connection struct {
@@ -413,7 +386,7 @@ func (c *Connection) writeMessage(w io.Writer, message *iso8583.Message) error {
413
386
// default message writer
414
387
packed , err := message .Pack ()
415
388
if err != nil {
416
- return utils . NewSafeError ( & PackError { err }, "failed to pack message" )
389
+ return fmt . Errorf ( "packing message: %w" , err )
417
390
}
418
391
419
392
// create buffer for header and packed message so we can write it to
@@ -536,7 +509,7 @@ func (c *Connection) writeLoop() {
536
509
if err != nil {
537
510
c .handleError (fmt .Errorf ("writing message: %w" , err ))
538
511
539
- var packErr * PackError
512
+ var packErr * iso8583. PackError
540
513
if errors .As (err , & packErr ) {
541
514
// let caller know that the message was not sent because of pack error.
542
515
// We don't set all type of errors to errCh as this case is handled
@@ -587,9 +560,9 @@ func (c *Connection) readLoop() {
587
560
if err != nil {
588
561
c .handleError (utils .NewSafeError (err , "failed to read message from connection" ))
589
562
590
- // if err is ErrUnpack , we can still continue reading
563
+ // if err is UnpackError , we can still continue reading
591
564
// from the connection
592
- var unpackErr * UnpackError
565
+ var unpackErr * iso8583. UnpackError
593
566
if errors .As (err , & unpackErr ) {
594
567
continue
595
568
}
@@ -635,11 +608,7 @@ func (c *Connection) readMessage(r io.Reader) (*iso8583.Message, error) {
635
608
message := iso8583 .NewMessage (c .spec )
636
609
err = message .Unpack (rawMessage )
637
610
if err != nil {
638
- unpackErr := & UnpackError {
639
- Err : err ,
640
- RawMessage : rawMessage ,
641
- }
642
- return nil , fmt .Errorf ("unpacking message: %w" , unpackErr )
611
+ return nil , fmt .Errorf ("unpacking message: %w" , err )
643
612
}
644
613
645
614
return message , nil
0 commit comments