Skip to content

Commit 2490a94

Browse files
authored
Merge pull request #24 from honeycombio/jharley.add-error-source-field
add 'source' to error object
2 parents 49e11fe + 3526b7b commit 2490a94

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

errors.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,26 @@ 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+
// Only one field should be populated depending on the source of the error.
54+
type ErrorSource struct {
55+
// Pointer is a JSON Pointer (RFC6901) indicating the value in the request document that caused the error.
56+
Pointer string `json:"pointer,omitempty"`
57+
58+
// Parameter is a string indicating which query or path parameter caused the error.
59+
Parameter string `json:"parameter,omitempty"`
60+
61+
// Header is a string indicating the name of a single request header which caused the error.
62+
Header string `json:"header,omitempty"`
63+
}
64+
4965
// Error implements the `Error` interface.
5066
func (e *ErrorObject) Error() string {
5167
return fmt.Sprintf("Error: %s %s\n", e.Title, e.Detail)

errors_test.go

Lines changed: 2 additions & 2 deletions
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)