Skip to content

Commit

Permalink
Added wrapped errors in builder, fixed message formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
xBlaz3kx committed Dec 13, 2024
1 parent 7fd33f5 commit b65262c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"

"github.com/pkg/errors"
"github.com/samber/lo"
)

Expand Down Expand Up @@ -122,24 +123,24 @@ func (b *Builder) Build() (*string, error) {
// Validate payload
err := b.payload.Validate()
if err != nil {
return nil, err
return nil, errors.Wrap(err, "payload validation failed")
}

// Sign payload with private key
err = b.signature.Sign(b.payload, b.privateKey)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "failed to sign message")
}

payload, err := json.Marshal(b.payload)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "failed to marshal payload")
}

signature, err := json.Marshal(b.signature)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "failed to marshal signature")
}

return lo.ToPtr(fmt.Sprintf("OCMF|%v|%v", payload, signature)), nil
return lo.ToPtr(fmt.Sprintf("OCMF|%s|%s", payload, signature)), nil
}

0 comments on commit b65262c

Please sign in to comment.