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 wrong response data #325

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 18 additions & 3 deletions cmd/server/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,12 @@ func deleteFile(logger log.Logger, repo ICLFileRepository) http.HandlerFunc {

w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(`{"error": null}`)

type response struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you define this as a reusable type instead of duplicating it inside each method? Something like type ErrorResponse struct.

Error error `json:"error"`
}

json.NewEncoder(w).Encode(&response{Error: nil})
}
}

Expand Down Expand Up @@ -369,7 +374,12 @@ func validateFile(logger log.Logger, repo ICLFileRepository) http.HandlerFunc {

w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(`{"error": null}`)

type response struct {
Error error `json:"error"`
}

json.NewEncoder(w).Encode(&response{Error: nil})
}
}

Expand Down Expand Up @@ -474,6 +484,11 @@ func removeCashLetterFromFile(logger log.Logger, repo ICLFileRepository) http.Ha

w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(`{"error": null}`)

type response struct {
Error error `json:"error"`
}

json.NewEncoder(w).Encode(&response{Error: nil})
}
}
2 changes: 1 addition & 1 deletion cmd/server/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func TestFiles_validateFile(t *testing.T) {
w.Flush()

require.Equal(t, http.StatusOK, w.Code, w.Body)
assert.Contains(t, w.Body.String(), `"{\"error\": null}"`)
assert.Contains(t, w.Body.String(), `{"error":null}`)
})

t.Run("invalid file", func(t *testing.T) {
Expand Down
5 changes: 1 addition & 4 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ func Passthrough(lineIn string) (lineOut string) {

// DecodeEBCDIC will decode a line from EBCDIC-0037 to UTF-8
func DecodeEBCDIC(lineIn string) (lineOut string) {
lineOut, err := encoding.EBCDIC.NewDecoder().String(lineIn)
if err != nil {
fmt.Printf("Error decoding '%X' as EBCDIC: %v\n", lineIn, err)
}
lineOut, _ = encoding.EBCDIC.NewDecoder().String(lineIn)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been fixed on master. Will you rebase or merge master into your branch and accept that version?

return lineOut
}

Expand Down
Loading