Add default message for TApplicationException since some implementations may not set message field

Client: go

This closes #1335
This commit is contained in:
damnever 2017-09-05 13:14:06 +08:00 committed by James E. King, III
parent fcb2f5a8f4
commit 1b20b18ec0
2 changed files with 16 additions and 2 deletions

View File

@ -30,6 +30,17 @@ const (
PROTOCOL_ERROR = 7 PROTOCOL_ERROR = 7
) )
var defaultApplicationExceptionMessage = map[int32]string{
UNKNOWN_APPLICATION_EXCEPTION: "unknown application exception",
UNKNOWN_METHOD: "unknown method",
INVALID_MESSAGE_TYPE_EXCEPTION: "invalid message type",
WRONG_METHOD_NAME: "wrong method name",
BAD_SEQUENCE_ID: "bad sequence ID",
MISSING_RESULT: "missing result",
INTERNAL_ERROR: "unknown internal error",
PROTOCOL_ERROR: "unknown protocol error",
}
// Application level Thrift exception // Application level Thrift exception
type TApplicationException interface { type TApplicationException interface {
TException TException
@ -44,7 +55,10 @@ type tApplicationException struct {
} }
func (e tApplicationException) Error() string { func (e tApplicationException) Error() string {
if e.message != "" {
return e.message return e.message
}
return defaultApplicationExceptionMessage[e.type_]
} }
func NewTApplicationException(type_ int32, message string) TApplicationException { func NewTApplicationException(type_ int32, message string) TApplicationException {

View File

@ -25,7 +25,7 @@ import (
func TestTApplicationException(t *testing.T) { func TestTApplicationException(t *testing.T) {
exc := NewTApplicationException(UNKNOWN_APPLICATION_EXCEPTION, "") exc := NewTApplicationException(UNKNOWN_APPLICATION_EXCEPTION, "")
if exc.Error() != "" { if exc.Error() != defaultApplicationExceptionMessage[UNKNOWN_APPLICATION_EXCEPTION] {
t.Fatalf("Expected empty string for exception but found '%s'", exc.Error()) t.Fatalf("Expected empty string for exception but found '%s'", exc.Error())
} }
if exc.TypeId() != UNKNOWN_APPLICATION_EXCEPTION { if exc.TypeId() != UNKNOWN_APPLICATION_EXCEPTION {