Skip to content

Commit 0f98d6c

Browse files
committed
v1.3.0 because of http error codes fixes
1 parent 37924c5 commit 0f98d6c

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

main.go

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
_ "github.com/mattn/go-sqlite3"
1818
)
1919

20-
const version = "1.2.0"
20+
const version = "1.3.0"
2121

2222
func main() {
2323
err := cmd(os.Args[1:])
@@ -110,8 +110,11 @@ func initQueryHandler(dbPath string, queryString string, serverPort uint) (func(
110110
if err == io.EOF || err == http.ErrBodyReadAfterClose /* last line is without \n */ {
111111
break
112112
} else if err != nil {
113-
http.Error(w,
114-
fmt.Sprintf("\n\nError reading request body: %v\n\n%s", err, helpMessage), http.StatusInternalServerError)
113+
http.Error(
114+
w,
115+
fmt.Sprintf("\n\nError reading request body: %v\n\n%s", err, helpMessage),
116+
http.StatusInternalServerError,
117+
)
115118
return
116119
}
117120

@@ -125,16 +128,22 @@ func initQueryHandler(dbPath string, queryString string, serverPort uint) (func(
125128

126129
rows, err := queryStmt.Query(queryParams...)
127130
if err != nil {
128-
msg := fmt.Sprintf("\n\nError executing query for params %#v: %v\n\n%s", csvLine, err, helpMessage)
129-
http.Error(w, msg, http.StatusInternalServerError)
131+
http.Error(
132+
w,
133+
fmt.Sprintf("\n\nError executing query for params %#v: %v\n\n%s", csvLine, err, helpMessage),
134+
http.StatusInternalServerError,
135+
)
130136
return
131137
}
132138
defer rows.Close()
133139

134140
cols, err := rows.Columns()
135141
if err != nil {
136-
msg := fmt.Sprintf("\n\nError reading columns for query with params %#v: %v\n\n%s", csvLine, err, helpMessage)
137-
http.Error(w, msg, http.StatusInternalServerError)
142+
http.Error(
143+
w,
144+
fmt.Sprintf("\n\nError reading columns for query with params %#v: %v\n\n%s", csvLine, err, helpMessage),
145+
http.StatusInternalServerError,
146+
)
138147
return
139148
}
140149

@@ -151,17 +160,23 @@ func initQueryHandler(dbPath string, queryString string, serverPort uint) (func(
151160

152161
err = rows.Scan(pointers...)
153162
if err != nil {
154-
http.Error(w,
155-
fmt.Sprintf("\n\nError reading query results for params %#v: %v\n\n%s", csvLine, err, helpMessage), http.StatusInternalServerError)
163+
http.Error(
164+
w,
165+
fmt.Sprintf("\n\nError reading query results for params %#v: %v\n\n%s", csvLine, err, helpMessage),
166+
http.StatusInternalServerError,
167+
)
156168
return
157169
}
158170

159171
queryAnswer.Out = append(queryAnswer.Out, row)
160172
}
161173
err = rows.Err()
162174
if err != nil {
163-
http.Error(w,
164-
fmt.Sprintf("\n\nError executing query: %v\n\n%s", err, helpMessage), http.StatusInternalServerError)
175+
http.Error(
176+
w,
177+
fmt.Sprintf("\n\nError executing query: %v\n\n%s", err, helpMessage),
178+
http.StatusInternalServerError,
179+
)
165180
return
166181
}
167182

@@ -173,19 +188,21 @@ func initQueryHandler(dbPath string, queryString string, serverPort uint) (func(
173188

174189
answerJSON, err := json.Marshal(answer)
175190
if err != nil {
176-
http.Error(w,
191+
http.Error(
192+
w,
177193
fmt.Sprintf("\n\nError encoding json: %v\n\n%s", err, helpMessage),
178-
http.StatusInternalServerError)
194+
http.StatusInternalServerError,
195+
)
179196
return
180197
}
181198

182199
_, err = w.Write(answerJSON)
183200
if err != nil {
184-
log.Printf("Query: error 500 - cannot send json to client: %v\n", err)
185-
186-
http.Error(w,
201+
http.Error(
202+
w,
187203
fmt.Sprintf("\n\nError sending json to client: %v\n\n%s", err, helpMessage),
188-
http.StatusInternalServerError)
204+
http.StatusInternalServerError,
205+
)
189206
return
190207
}
191208
}, nil

0 commit comments

Comments
 (0)