Skip to content

Commit

Permalink
fix: Remove JSONErrorUnauthorized (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrisch06 committed Jul 10, 2023
1 parent 2e95016 commit d40cc47
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
14 changes: 0 additions & 14 deletions json_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,13 @@ type PageDetails struct {
TotalSize int `json:"totalSize,omitempty"`
}

// JSONErrorUnauthorized is a generic 401 unauthorized response
var JSONErrorUnauthorized = &Error{
Code: http.StatusUnauthorized,
Message: "Unauthorized",
}

// Response is the top level container of all of our REST API responses.
type Response struct {
Data interface{} `json:"data,omitempty"`
Page *PageDetails `json:"page,omitempty"`
Error *Error `json:"error,omitempty"`
}

// NewError returns an error that contains the given code and message.
func NewError(code int, message string) *Error {
return &Error{
Code: code,
Message: message,
}
}

func encodeResponse(w http.ResponseWriter, jr Response, code int) error {
// We _could_ encode the JSON directly to the response, but in so doing, the response code is
// written out the first time Write() is called under the hood. This makes it difficult to
Expand Down
2 changes: 1 addition & 1 deletion json_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestError(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
je := NewError(tt.code, tt.message)
je := &Error{Code: tt.code, Message: tt.message}
if je.Code != tt.code {
t.Errorf("got code %v, want %v", je.Code, tt.code)
}
Expand Down

0 comments on commit d40cc47

Please sign in to comment.