Commit 9c527942 authored by Tomas's avatar Tomas
Browse files

ErrorCode -> ErrorType

parent 58a6c98c
......@@ -19,13 +19,13 @@ type Version string
// Action encodes the session type of an IRMA session (e.g., disclosing).
type Action string
// ErrorCode are session errors.
type ErrorCode string
// ErrorType are session errors.
type ErrorType string
// SessionError is a protocol error.
type SessionError struct {
Err error
ErrorCode
ErrorType
*ApiError
Info string
Status int
......@@ -77,34 +77,34 @@ const (
// Protocol errors
const (
// Protocol version not supported
ErrorProtocolVersionNotSupported = ErrorCode("protocolVersionNotSupported")
ErrorProtocolVersionNotSupported = ErrorType("protocolVersionNotSupported")
// Error in HTTP communication
ErrorTransport = ErrorCode("transport")
ErrorTransport = ErrorType("transport")
// Invalid client JWT in first IRMA message
ErrorInvalidJWT = ErrorCode("invalidJwt")
ErrorInvalidJWT = ErrorType("invalidJwt")
// Unkown session type (not disclosing, signing, or issuing)
ErrorUnknownAction = ErrorCode("unknownAction")
ErrorUnknownAction = ErrorType("unknownAction")
// Crypto error during calculation of our response (second IRMA message)
ErrorCrypto = ErrorCode("crypto")
ErrorCrypto = ErrorType("crypto")
// Server rejected our response (second IRMA message)
ErrorRejected = ErrorCode("rejected")
ErrorRejected = ErrorType("rejected")
// (De)serializing of a message failed
ErrorSerialization = ErrorCode("serialization")
ErrorSerialization = ErrorType("serialization")
// Error in keyshare protocol
ErrorKeyshare = ErrorCode("keyshare")
ErrorKeyshare = ErrorType("keyshare")
// Keyshare server has blocked us
ErrorKeyshareBlocked = ErrorCode("keyshareBlocked")
ErrorKeyshareBlocked = ErrorType("keyshareBlocked")
// API server error
ErrorApi = ErrorCode("api")
ErrorApi = ErrorType("api")
// Server returned unexpected or malformed response
ErrorServerResponse = ErrorCode("serverResponse")
ErrorServerResponse = ErrorType("serverResponse")
)
func (e *SessionError) Error() string {
if e.Err != nil {
return fmt.Sprintf("%s: %s", string(e.ErrorCode), e.Err.Error())
return fmt.Sprintf("%s: %s", string(e.ErrorType), e.Err.Error())
}
return string(e.ErrorCode)
return string(e.ErrorType)
}
func jwtDecode(jwt string, body interface{}) (string, error) {
......
......@@ -95,7 +95,7 @@ func NewSession(credManager *CredentialManager, qr *Qr, handler Handler) {
}
version, err := calcVersion(qr)
if err != nil {
session.fail(&SessionError{ErrorCode: ErrorProtocolVersionNotSupported, Err: err})
session.fail(&SessionError{ErrorType: ErrorProtocolVersionNotSupported, Err: err})
return
}
session.Version = Version(version)
......@@ -108,7 +108,7 @@ func NewSession(credManager *CredentialManager, qr *Qr, handler Handler) {
case ActionUnknown:
fallthrough
default:
session.fail(&SessionError{ErrorCode: ErrorUnknownAction, Info: string(session.Action)})
session.fail(&SessionError{ErrorType: ErrorUnknownAction, Info: string(session.Action)})
return
}
......@@ -144,7 +144,7 @@ func (session *session) start() {
var err error
session.jwt, server, err = parseRequestorJwt(session.Action, session.info.Jwt)
if err != nil {
session.fail(&SessionError{ErrorCode: ErrorInvalidJWT, Err: err})
session.fail(&SessionError{ErrorType: ErrorInvalidJWT, Err: err})
return
}
session.irmaSession = session.jwt.IrmaSession()
......@@ -203,7 +203,7 @@ func (session *session) do(proceed bool) {
message, err = session.credManager.IssueCommitments(session.irmaSession.(*IssuanceRequest))
}
if err != nil {
session.fail(&SessionError{ErrorCode: ErrorCrypto, Err: err})
session.fail(&SessionError{ErrorType: ErrorCrypto, Err: err})
return
}
session.sendResponse(message)
......@@ -219,7 +219,7 @@ func (session *session) do(proceed bool) {
builders, err = session.credManager.IssuanceProofBuilders(session.irmaSession.(*IssuanceRequest))
}
if err != nil {
session.fail(&SessionError{ErrorCode: ErrorCrypto, Err: err})
session.fail(&SessionError{ErrorType: ErrorCrypto, Err: err})
}
startKeyshareSession(session.credManager, session.irmaSession, builders, session, session.Handler)
......@@ -236,11 +236,11 @@ func (session *session) KeyshareCancelled() {
}
func (session *session) KeyshareBlocked(duration int) {
session.fail(&SessionError{ErrorCode: ErrorKeyshareBlocked, Info: strconv.Itoa(duration)})
session.fail(&SessionError{ErrorType: ErrorKeyshareBlocked, Info: strconv.Itoa(duration)})
}
func (session *session) KeyshareError(err error) {
session.fail(&SessionError{ErrorCode: ErrorKeyshare, Err: err})
session.fail(&SessionError{ErrorType: ErrorKeyshare, Err: err})
}
type disclosureResponse string
......@@ -259,7 +259,7 @@ func (session *session) sendResponse(message interface{}) {
return
}
if response != "VALID" {
session.fail(&SessionError{ErrorCode: ErrorRejected, Info: string(response)})
session.fail(&SessionError{ErrorType: ErrorRejected, Info: string(response)})
return
}
log, _ = session.createLogEntry(message.(gabi.ProofList)) // TODO err
......@@ -270,7 +270,7 @@ func (session *session) sendResponse(message interface{}) {
return
}
if err = session.credManager.ConstructCredentials(response, session.irmaSession.(*IssuanceRequest)); err != nil {
session.fail(&SessionError{ErrorCode: ErrorCrypto, Err: err})
session.fail(&SessionError{ErrorType: ErrorCrypto, Err: err})
return
}
log, _ = session.createLogEntry(message) // TODO err
......
......@@ -35,7 +35,7 @@ func (th TestHandler) Failure(action Action, err *SessionError) {
}
func (th TestHandler) UnsatisfiableRequest(action Action, missing AttributeDisjunctionList) {
th.c <- &SessionError{
ErrorCode: ErrorCode("UnsatisfiableRequest"),
ErrorType: ErrorType("UnsatisfiableRequest"),
}
}
func (th TestHandler) AskVerificationPermission(request DisclosureRequest, ServerName string, callback PermissionHandler) {
......
......@@ -57,7 +57,7 @@ func (transport *HTTPTransport) request(url string, method string, result interf
} else {
marshaled, err := json.Marshal(object)
if err != nil {
return &SessionError{ErrorCode: ErrorSerialization, Err: err}
return &SessionError{ErrorType: ErrorSerialization, Err: err}
}
if verbose {
fmt.Printf("%s %s: %s\n", method, url, string(marshaled))
......@@ -72,7 +72,7 @@ func (transport *HTTPTransport) request(url string, method string, result interf
req, err := http.NewRequest(method, transport.Server+url, reader)
if err != nil {
return &SessionError{ErrorCode: ErrorTransport, Err: err}
return &SessionError{ErrorType: ErrorTransport, Err: err}
}
req.Header.Set("User-Agent", "irmago")
......@@ -89,7 +89,7 @@ func (transport *HTTPTransport) request(url string, method string, result interf
res, err := transport.client.Do(req)
if err != nil {
return &SessionError{ErrorCode: ErrorTransport, Err: err}
return &SessionError{ErrorType: ErrorTransport, Err: err}
}
if method == http.MethodDelete {
......@@ -98,18 +98,18 @@ func (transport *HTTPTransport) request(url string, method string, result interf
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return &SessionError{ErrorCode: ErrorServerResponse, Err: err, Status: res.StatusCode}
return &SessionError{ErrorType: ErrorServerResponse, Err: err, Status: res.StatusCode}
}
if res.StatusCode != 200 {
apierr := &ApiError{}
json.Unmarshal(body, apierr)
if apierr.ErrorName == "" { // Not an ApiErrorMessage
return &SessionError{ErrorCode: ErrorServerResponse, Status: res.StatusCode}
return &SessionError{ErrorType: ErrorServerResponse, Status: res.StatusCode}
}
if verbose {
fmt.Printf("ERROR: %+v\n", apierr)
}
return &SessionError{ErrorCode: ErrorApi, Status: res.StatusCode, ApiError: apierr}
return &SessionError{ErrorType: ErrorApi, Status: res.StatusCode, ApiError: apierr}
}
if verbose {
......@@ -120,7 +120,7 @@ func (transport *HTTPTransport) request(url string, method string, result interf
} else {
err = json.Unmarshal(body, result)
if err != nil {
return &SessionError{ErrorCode: ErrorServerResponse, Err: err, Status: res.StatusCode}
return &SessionError{ErrorType: ErrorServerResponse, Err: err, Status: res.StatusCode}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment