updated as per the review comments

This commit is contained in:
MohitKatare-protean
2025-03-30 19:13:02 +05:30
parent 244a7be7c1
commit f0e39e34e7
35 changed files with 1605 additions and 124 deletions

View File

@@ -7,48 +7,9 @@ import (
"fmt"
"net/http"
"strings"
"github.com/beckn/beckn-onix/pkg/model"
)
// Error represents a standardized error response used across the system.
type Error struct {
// Code is a short, machine-readable error code.
Code string `json:"code,omitempty"`
// Message provides a human-readable description of the error.
Message string `json:"message,omitempty"`
// Paths indicates the specific field(s) or endpoint(s) related to the error.
Paths string `json:"paths,omitempty"`
}
// SchemaValidationErr represents a collection of schema validation failures.
type SchemaValidationErr struct {
Errors []Error
}
// Error implements the error interface for SchemaValidationErr.
func (e *SchemaValidationErr) Error() string {
var errorMessages []string
for _, err := range e.Errors {
errorMessages = append(errorMessages, fmt.Sprintf("%s: %s", err.Paths, err.Message))
}
return strings.Join(errorMessages, "; ")
}
// Message represents a standard message structure with acknowledgment and error information.
type Message struct {
// Ack contains the acknowledgment status of the response.
Ack struct {
Status string `json:"status,omitempty"`
} `json:"ack,omitempty"`
// Error holds error details if any occurred during processing.
Error *Error `json:"error,omitempty"`
}
// SendAck sends an acknowledgment response (ACK) to the client.
func SendAck(w http.ResponseWriter) {
resp := &model.Response{

View File

@@ -126,21 +126,6 @@ func TestSendNack(t *testing.T) {
}
}
func TestSchemaValidationErr_Error(t *testing.T) {
// Create sample validation errors
validationErrors := []Error{
{Paths: "name", Message: "Name is required"},
{Paths: "email", Message: "Invalid email format"},
}
err := SchemaValidationErr{Errors: validationErrors}
expected := "name: Name is required; email: Invalid email format"
if err.Error() != expected {
t.Errorf("err.Error() = %s, want %s",
err.Error(), expected)
}
}
func compareJSON(expected, actual map[string]interface{}) bool {
expectedBytes, _ := json.Marshal(expected)
actualBytes, _ := json.Marshal(actual)