Skip to content

Commit a31b22b

Browse files
committed
add 'source' to error object
1 parent 49e11fe commit a31b22b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Diff for: errors.go

+15
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,25 @@ type ErrorObject struct {
4242
// Code is an application-specific error code, expressed as a string value.
4343
Code string `json:"code,omitempty"`
4444

45+
// Source is an object containing references to the primary source of the error.
46+
Source *ErrorSource `json:"source,omitempty"`
47+
4548
// Meta is an object containing non-standard meta-information about the error.
4649
Meta *map[string]interface{} `json:"meta,omitempty"`
4750
}
4851

52+
// ErrorSource is an object containing references to the primary source of the error.
53+
type ErrorSource struct {
54+
// Pointer is a string indicating the value in the request document that caused the error.
55+
Pointer string `json:"pointer,omitempty"`
56+
57+
// Parameter is a string indicating which query or path parameter caused the error.
58+
Parameter string `json:"parameter,omitempty"`
59+
60+
// Header is a string indicating the name of a single request header which caused the error.
61+
Header string `json:"header,omitempty"`
62+
}
63+
4964
// Error implements the `Error` interface.
5065
func (e *ErrorObject) Error() string {
5166
return fmt.Sprintf("Error: %s %s\n", e.Title, e.Detail)

Diff for: errors_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func TestMarshalErrorsWritesTheExpectedPayload(t *testing.T) {
2828
}{
2929
{
3030
Title: "TestFieldsAreSerializedAsNeeded",
31-
In: []*ErrorObject{{ID: "0", Title: "Test title.", Detail: "Test detail", Status: "400", Code: "E1100"}},
31+
In: []*ErrorObject{{ID: "0", Title: "Test title.", Detail: "Test detail", Status: "400", Code: "E1100", Source: &ErrorSource{Pointer: "title"}}},
3232
Out: map[string]interface{}{"errors": []interface{}{
33-
map[string]interface{}{"id": "0", "title": "Test title.", "detail": "Test detail", "status": "400", "code": "E1100"},
33+
map[string]interface{}{"id": "0", "title": "Test title.", "detail": "Test detail", "status": "400", "code": "E1100", "source": map[string]interface{}{"pointer": "title"}},
3434
}},
3535
},
3636
{

0 commit comments

Comments
 (0)