@rivascva/dt-idl 1.1.50 → 1.1.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -24,13 +24,13 @@ type Responder[T ~string] interface {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
type StandardResponder[T ~string] struct {
|
|
27
|
-
|
|
27
|
+
logger logger.Logger
|
|
28
28
|
defaultCode T
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
func NewStandardResponder[T ~string](
|
|
31
|
+
func NewStandardResponder[T ~string](logger logger.Logger, defaultCode T) *StandardResponder[T] {
|
|
32
32
|
return &StandardResponder[T]{
|
|
33
|
-
|
|
33
|
+
logger: logger,
|
|
34
34
|
defaultCode: defaultCode,
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -39,7 +39,7 @@ func (r *StandardResponder[T]) Write(w http.ResponseWriter, status int, data any
|
|
|
39
39
|
// encode the given data object
|
|
40
40
|
out, err := json.Marshal(data)
|
|
41
41
|
if err != nil {
|
|
42
|
-
r.
|
|
42
|
+
r.logger.Error(fmt.Errorf("Write: failed to marshal the data: %w", err))
|
|
43
43
|
r.WriteError(w, http.StatusInternalServerError, "error encoding the data")
|
|
44
44
|
return
|
|
45
45
|
}
|
|
@@ -48,7 +48,7 @@ func (r *StandardResponder[T]) Write(w http.ResponseWriter, status int, data any
|
|
|
48
48
|
w.WriteHeader(status)
|
|
49
49
|
_, err = w.Write(out)
|
|
50
50
|
if err != nil {
|
|
51
|
-
r.
|
|
51
|
+
r.logger.Fatal(fmt.Errorf("Write: failed to write a response: %w", err))
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -64,13 +64,13 @@ func (r *StandardResponder[T]) WriteErrorWithCode(w http.ResponseWriter, status
|
|
|
64
64
|
Message: message,
|
|
65
65
|
})
|
|
66
66
|
if err != nil {
|
|
67
|
-
r.
|
|
67
|
+
r.logger.Fatal(fmt.Errorf("WriteErrorWithCode: failed to marshal the error: %w", err))
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
// write the data to the given writer
|
|
71
71
|
w.WriteHeader(status)
|
|
72
72
|
_, err = w.Write(out)
|
|
73
73
|
if err != nil {
|
|
74
|
-
r.
|
|
74
|
+
r.logger.Fatal(fmt.Errorf("WriteErrorWithCode: failed to write a response: %w", err))
|
|
75
75
|
}
|
|
76
76
|
}
|