watchtower/wtwire/error_code: add human-readable descriptors

This commit is contained in:
Conner Fromknecht 2019-03-15 02:29:55 -07:00
parent 9c70f49901
commit 99dbbf48aa
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

@ -1,5 +1,7 @@
package wtwire
import "fmt"
// ErrorCode represents a generic error code used when replying to watchtower
// clients. Specific reply messages may extend the ErrorCode primitive and add
// custom codes, so long as they don't collide with the generic error codes..
@ -18,3 +20,33 @@ const (
// permanently failed, and further communication should be avoided.
CodePermanentFailure ErrorCode = 50
)
// String returns a human-readable description of an ErrorCode.
func (c ErrorCode) String() string {
switch c {
case CodeOK:
return "CodeOK"
case CodeTemporaryFailure:
return "CodeTemporaryFailure"
case CodePermanentFailure:
return "CodePermanentFailure"
case CreateSessionCodeAlreadyExists:
return "CreateSessionCodeAlreadyExists"
case CreateSessionCodeRejectMaxUpdates:
return "CreateSessionCodeRejectMaxUpdates"
case CreateSessionCodeRejectRewardRate:
return "CreateSessionCodeRejectRewardRate"
case CreateSessionCodeRejectSweepFeeRate:
return "CreateSessionCodeRejectSweepFeeRate"
case CreateSessionCodeRejectBlobType:
return "CreateSessionCodeRejectBlobType"
case StateUpdateCodeClientBehind:
return "StateUpdateCodeClientBehind"
case StateUpdateCodeMaxUpdatesExceeded:
return "StateUpdateCodeMaxUpdatesExceeded"
case StateUpdateCodeSeqNumOutOfOrder:
return "StateUpdateCodeSeqNumOutOfOrder"
default:
return fmt.Sprintf("UnknownErrorCode: %d", c)
}
}