-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
60 lines (50 loc) · 1.38 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package awsmocker
import (
"encoding/xml"
"fmt"
"net/http"
)
// aws/protocol/restjson/decoder_util.go
type errorResponse struct {
XMLName xml.Name `xml:"ErrorResponse" json:"-"`
Type string `xml:"Error>Type" json:"-"`
Code string `xml:"Error>Code" json:"code"`
Message string `xml:"Error>Message" json:"message"`
RequestId string `xml:"RequestId" json:"-"`
statusCode int `xml:"-" json:"-"`
}
func (e *errorResponse) getResponse(rr *ReceivedRequest) *httpResponse {
if e.statusCode == 0 {
e.statusCode = http.StatusBadRequest
// e.statusCode = http.StatusTeapot
}
switch rr.AssumedResponseType {
case ContentTypeJSON:
return &httpResponse{
contentType: ContentTypeJSON,
Body: EncodeAsJson(e),
StatusCode: e.statusCode, // 501
}
case ContentTypeXML:
return &httpResponse{
contentType: ContentTypeXML,
Body: encodeAsXml(e),
StatusCode: e.statusCode, // 501
}
default:
return &httpResponse{
contentType: ContentTypeText,
Body: fmt.Sprintf("ERROR! %s: %s", e.Code, e.Message),
StatusCode: e.statusCode, // 501
}
}
}
func generateErrorStruct(statusCode int, code string, message string, args ...any) *errorResponse {
return &errorResponse{
Type: "Sender",
Code: code,
Message: fmt.Sprintf(message, args...),
RequestId: "7a62c49f-347e-4fc4-9331-6e8eEXAMPLE",
statusCode: statusCode,
}
}