fixed error handling

This commit is contained in:
Apfel 2019-03-14 02:56:18 +01:00
parent 482c9dc5f6
commit fb3099169e

40
main.go
View File

@ -39,9 +39,9 @@ const (
) )
// CheckError makes error handling not as ugly and inefficient. // CheckError makes error handling not as ugly and inefficient.
func CheckError(e error) { func CheckError(err error) {
if e != nil { if err != nil {
log.Fatal("WiiSOAP forgot how to drive and suddenly crashed! Reason: ", e) log.Fatalf("WiiSOAP forgot how to drive and suddenly crashed! Reason: %s\n", err.Error())
} }
} }
@ -71,7 +71,7 @@ func main() {
CheckError(err) CheckError(err)
// Start the HTTP server. // Start the HTTP server.
fmt.Printf("Starting HTTP connection (%s)...\nNot using the usual port for HTTP? Be sure to use a proxy, otherwise the Wii can't connect!", CON.Address) fmt.Printf("Starting HTTP connection (%s)...\nNot using the usual port for HTTP?\nBe sure to use a proxy, otherwise the Wii can't connect!\n", CON.Address)
http.HandleFunc("/", handler) // each request calls handler http.HandleFunc("/", handler) // each request calls handler
log.Fatal(http.ListenAndServe(CON.Address, nil)) log.Fatal(http.ListenAndServe(CON.Address, nil))
@ -97,9 +97,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "CheckDeviceStatus": case "CheckDeviceStatus":
fmt.Println("CDS.") fmt.Println("CDS.")
CDS := CDS{} CDS := CDS{}
if err = xml.Unmarshal(body, &CDS); os.IsExist(err) { if err = xml.Unmarshal(body, &CDS); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "You need to POST some SOAP from WSC if you wanna get some, honey. ;)") fmt.Fprint(w, "You need to POST some SOAP from WSC if you wanna get some, honey. ;3")
return return
} }
fmt.Println(CDS) fmt.Println(CDS)
@ -131,9 +131,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "NotifiedETicketsSynced": case "NotifiedETicketsSynced":
fmt.Println("NETS") fmt.Println("NETS")
NETS := NETS{} NETS := NETS{}
if err = xml.Unmarshal(body, &NETS); os.IsExist(err) { if err = xml.Unmarshal(body, &NETS); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "This is a disgusting request, but 20 dollars is 20 dollars. ;)") fmt.Fprint(w, "This is a disgusting request, but 20 dollars is 20 dollars. ;3")
fmt.Printf("error: %v", err) fmt.Printf("error: %v", err)
return return
} }
@ -159,9 +159,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "ListETickets": case "ListETickets":
fmt.Println("LET") fmt.Println("LET")
LET := LET{} LET := LET{}
if err = xml.Unmarshal(body, &LET); os.IsExist(err) { if err = xml.Unmarshal(body, &LET); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "This is a disgusting request, but 20 dollars is 20 dollars. ;)") fmt.Fprint(w, "This is a disgusting request, but 20 dollars is 20 dollars. ;3")
fmt.Printf("error: %v", err) fmt.Printf("error: %v", err)
return return
} }
@ -190,9 +190,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "PurchaseTitle": case "PurchaseTitle":
fmt.Println("PT") fmt.Println("PT")
PT := PT{} PT := PT{}
if err = xml.Unmarshal(body, &PT); os.IsExist(err) { if err = xml.Unmarshal(body, &PT); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "if you wanna fun time, its gonna cost ya extra sweetie. ;)") fmt.Fprint(w, "if you wanna fun time, its gonna cost ya extra sweetie. ;3")
fmt.Printf("Error: %s", err.Error()) fmt.Printf("Error: %s", err.Error())
return return
} }
@ -232,9 +232,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "CheckRegistration": case "CheckRegistration":
fmt.Println("CR.") fmt.Println("CR.")
CR := CR{} CR := CR{}
if err = xml.Unmarshal(body, &CR); os.IsExist(err) { if err = xml.Unmarshal(body, &CR); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "not good enough for me. ;)") fmt.Fprint(w, "not good enough for me. ;3")
fmt.Printf("Error: %s", err.Error()) fmt.Printf("Error: %s", err.Error())
return return
} }
@ -262,9 +262,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "GetRegistrationInfo": case "GetRegistrationInfo":
fmt.Println("GRI.") fmt.Println("GRI.")
GRI := GRI{} GRI := GRI{}
if err = xml.Unmarshal(body, &GRI); os.IsExist(err) { if err = xml.Unmarshal(body, &GRI); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "how dirty. ;)") fmt.Fprint(w, "how dirty. ;3")
fmt.Printf("Error: %s", err.Error()) fmt.Printf("Error: %s", err.Error())
return return
} }
@ -298,9 +298,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "Register": case "Register":
fmt.Println("REG.") fmt.Println("REG.")
REG := REG{} REG := REG{}
if err = xml.Unmarshal(body, &REG); os.IsExist(err) { if err = xml.Unmarshal(body, &REG); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "disgustingly invalid. ;)") fmt.Fprint(w, "disgustingly invalid. ;3")
fmt.Printf("Error: %s", err.Error()) fmt.Printf("Error: %s", err.Error())
return return
} }
@ -331,9 +331,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
case "Unregister": case "Unregister":
fmt.Println("UNR.") fmt.Println("UNR.")
UNR := UNR{} UNR := UNR{}
if err = xml.Unmarshal(body, &UNR); os.IsExist(err) { if err = xml.Unmarshal(body, &UNR); err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "how abnormal... ;)") fmt.Fprint(w, "how abnormal... ;3")
fmt.Printf("Error: %s", err.Error()) fmt.Printf("Error: %s", err.Error())
return return
} }