File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ func main() {
41
41
r .HandleFunc ("/pagination/cursor_non_numeric" , pagination .HandleNonNumericCursor ).Methods (http .MethodGet )
42
42
r .HandleFunc ("/retries" , retries .HandleRetries ).Methods (http .MethodGet , http .MethodPost )
43
43
r .HandleFunc ("/retries/after" , retries .HandleRetries ).Methods (http .MethodGet )
44
- r .HandleFunc ("/errors/{status_code}" , errors .HandleErrors ).Methods (http .MethodGet )
44
+ r .HandleFunc ("/errors/{status_code}" , errors .HandleErrors ).Methods (http .MethodGet , http . MethodPost )
45
45
r .HandleFunc ("/optional" , acceptHeaders .HandleAcceptHeaderMultiplexing ).Methods (http .MethodGet )
46
46
r .HandleFunc ("/readonlyorwriteonly" , readonlywriteonly .HandleReadOrWrite ).Methods (http .MethodPost )
47
47
r .HandleFunc ("/readonlyandwriteonly" , readonlywriteonly .HandleReadAndWrite ).Methods (http .MethodPost )
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package errors
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "io"
6
7
"net/http"
7
8
"strconv"
8
9
@@ -29,11 +30,27 @@ func HandleErrors(w http.ResponseWriter, r *http.Request) {
29
30
w .Header ().Set ("Content-Type" , "application/json" )
30
31
w .WriteHeader (statusCodeInt )
31
32
32
- if err := json .NewEncoder (w ).Encode (models.Error {
33
- Code : statusCode ,
34
- Message : "an error occurred" ,
35
- Type : "internal" ,
36
- }); err != nil {
33
+ var res interface {}
34
+ if r .Method == http .MethodPost {
35
+ body , err := io .ReadAll (r .Body )
36
+ if err != nil {
37
+ utils .HandleError (w , err )
38
+ return
39
+ }
40
+
41
+ if err := json .Unmarshal (body , & res ); err != nil {
42
+ utils .HandleError (w , err )
43
+ return
44
+ }
45
+ } else {
46
+ res = models.Error {
47
+ Code : statusCode ,
48
+ Message : "an error occurred" ,
49
+ Type : "internal" ,
50
+ }
51
+ }
52
+
53
+ if err := json .NewEncoder (w ).Encode (res ); err != nil {
37
54
utils .HandleError (w , err )
38
55
return
39
56
}
You can’t perform that action at this time.
0 commit comments