Browse Source

Fix some unsafe type assertions.

Fixes issue #7.
Caleb Spare 12 years ago
parent
commit
b275aa7123
1 changed files with 8 additions and 6 deletions
  1. 8 6
      src/ngrok/client/views/web/http.go

+ 8 - 6
src/ngrok/client/views/web/http.go

@@ -116,17 +116,19 @@ func makeBody(h http.Header, body []byte) SerializedBody {
 		case "text/xml":
 			err = xml.Unmarshal(body, new(XMLDoc))
 			if err != nil {
-				syntaxError := err.(*xml.SyntaxError)
-				// xml syntax errors only give us a line number, so we
-				// count to find an offset
-				b.ErrorOffset = offsetForLine(syntaxError.Line)
+				if syntaxError, ok := err.(*xml.SyntaxError); ok {
+					// xml syntax errors only give us a line number, so we
+					// count to find an offset
+					b.ErrorOffset = offsetForLine(syntaxError.Line)
+				}
 			}
 
 		case "application/json":
 			err = json.Unmarshal(body, new(json.RawMessage))
 			if err != nil {
-				syntaxError := err.(*json.SyntaxError)
-				b.ErrorOffset = int(syntaxError.Offset)
+				if syntaxError, ok := err.(*json.SyntaxError); ok {
+					b.ErrorOffset = int(syntaxError.Offset)
+				}
 			}
 
 		case "application/x-www-form-urlencoded":