Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove JSONErrorUnauthorized (#31) #56

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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