@@ -40,33 +40,6 @@ const (
4040 StatusUnknown Status = ""
4141)
4242
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-
7043// Connection represents an ISO 8583 Connection. Connection may be used
7144// by multiple goroutines simultaneously.
7245type Connection struct {
@@ -413,7 +386,7 @@ func (c *Connection) writeMessage(w io.Writer, message *iso8583.Message) error {
413386 // default message writer
414387 packed , err := message .Pack ()
415388 if err != nil {
416- return utils . NewSafeError ( & PackError { err }, "failed to pack message" )
389+ return fmt . Errorf ( "packing message: %w" , err )
417390 }
418391
419392 // create buffer for header and packed message so we can write it to
@@ -536,7 +509,7 @@ func (c *Connection) writeLoop() {
536509 if err != nil {
537510 c .handleError (fmt .Errorf ("writing message: %w" , err ))
538511
539- var packErr * PackError
512+ var packErr * iso8583. PackError
540513 if errors .As (err , & packErr ) {
541514 // let caller know that the message was not sent because of pack error.
542515 // We don't set all type of errors to errCh as this case is handled
@@ -587,9 +560,9 @@ func (c *Connection) readLoop() {
587560 if err != nil {
588561 c .handleError (utils .NewSafeError (err , "failed to read message from connection" ))
589562
590- // if err is ErrUnpack , we can still continue reading
563+ // if err is UnpackError , we can still continue reading
591564 // from the connection
592- var unpackErr * UnpackError
565+ var unpackErr * iso8583. UnpackError
593566 if errors .As (err , & unpackErr ) {
594567 continue
595568 }
@@ -635,11 +608,7 @@ func (c *Connection) readMessage(r io.Reader) (*iso8583.Message, error) {
635608 message := iso8583 .NewMessage (c .spec )
636609 err = message .Unpack (rawMessage )
637610 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 )
643612 }
644613
645614 return message , nil
0 commit comments