Commit d9f8152b authored by Tomas's avatar Tomas
Browse files

Error -> SessionError

parent e3e8f1f8
......@@ -22,8 +22,8 @@ type Action string
// ErrorCode are session errors.
type ErrorCode string
// Error is a protocol error.
type Error struct {
// SessionError is a protocol error.
type SessionError struct {
Err error
ErrorCode
*ApiError
......@@ -100,7 +100,7 @@ const (
ErrorServerResponse = ErrorCode("serverResponse")
)
func (e *Error) Error() string {
func (e *SessionError) Error() string {
if e.Err != nil {
return fmt.Sprintf("%s: %s", string(e.ErrorCode), e.Err.Error())
}
......
......@@ -19,7 +19,7 @@ type Handler interface {
StatusUpdate(action Action, status Status)
Success(action Action)
Cancelled(action Action)
Failure(action Action, err *Error)
Failure(action Action, err *SessionError)
UnsatisfiableRequest(action Action, missing AttributeDisjunctionList)
AskIssuancePermission(request IssuanceRequest, ServerName string, callback PermissionHandler)
......@@ -95,7 +95,7 @@ func NewSession(credManager *CredentialManager, qr *Qr, handler Handler) {
}
version, err := calcVersion(qr)
if err != nil {
session.fail(&Error{ErrorCode: ErrorProtocolVersionNotSupported, Err: err})
session.fail(&SessionError{ErrorCode: 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(&Error{ErrorCode: ErrorUnknownAction, Err: nil, Info: string(session.Action)})
session.fail(&SessionError{ErrorCode: ErrorUnknownAction, Err: nil, Info: string(session.Action)})
return
}
......@@ -121,7 +121,7 @@ func NewSession(credManager *CredentialManager, qr *Qr, handler Handler) {
return
}
func (session *session) fail(err *Error) {
func (session *session) fail(err *SessionError) {
session.transport.Delete()
err.Err = errors.Wrap(err.Err, 0)
session.Handler.Failure(session.Action, err)
......@@ -136,7 +136,7 @@ func (session *session) start() {
session.info = &SessionInfo{}
Err := session.transport.Get("jwt", session.info)
if Err != nil {
session.fail(Err.(*Error))
session.fail(Err.(*SessionError))
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(&Error{ErrorCode: ErrorInvalidJWT, Err: err})
session.fail(&SessionError{ErrorCode: 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(&Error{ErrorCode: ErrorCrypto, Err: err})
session.fail(&SessionError{ErrorCode: 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(&Error{ErrorCode: ErrorCrypto, Err: err})
session.fail(&SessionError{ErrorCode: 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(&Error{ErrorCode: ErrorKeyshareBlocked, Info: strconv.Itoa(duration)})
session.fail(&SessionError{ErrorCode: ErrorKeyshareBlocked, Info: strconv.Itoa(duration)})
}
func (session *session) KeyshareError(err error) {
session.fail(&Error{ErrorCode: ErrorKeyshare, Err: err})
session.fail(&SessionError{ErrorCode: ErrorKeyshare, Err: err})
}
type disclosureResponse string
......@@ -255,22 +255,22 @@ func (session *session) sendResponse(message interface{}) {
case ActionDisclosing:
var response disclosureResponse
if err = session.transport.Post("proofs", &response, message); err != nil {
session.fail(err.(*Error))
session.fail(err.(*SessionError))
return
}
if response != "VALID" {
session.fail(&Error{ErrorCode: ErrorRejected, Info: string(response)})
session.fail(&SessionError{ErrorCode: ErrorRejected, Info: string(response)})
return
}
log, err = session.createLogEntry(message.(gabi.ProofList)) // TODO err
case ActionIssuing:
response := []*gabi.IssueSignatureMessage{}
if err = session.transport.Post("commitments", &response, message); err != nil {
session.fail(err.(*Error))
session.fail(err.(*SessionError))
return
}
if err = session.credManager.ConstructCredentials(response, session.irmaSession.(*IssuanceRequest)); err != nil {
session.fail(&Error{Err: err, ErrorCode: ErrorCrypto})
session.fail(&SessionError{Err: err, ErrorCode: ErrorCrypto})
return
}
log, err = session.createLogEntry(message) // TODO err
......
......@@ -15,7 +15,7 @@ import (
type TestHandler struct {
t *testing.T
c chan *Error
c chan *SessionError
manager *CredentialManager
}
......@@ -24,9 +24,9 @@ func (th TestHandler) Success(action Action) {
th.c <- nil
}
func (th TestHandler) Cancelled(action Action) {
th.c <- &Error{}
th.c <- &SessionError{}
}
func (th TestHandler) Failure(action Action, err *Error) {
func (th TestHandler) Failure(action Action, err *SessionError) {
select {
case th.c <- err:
default:
......@@ -34,7 +34,7 @@ func (th TestHandler) Failure(action Action, err *Error) {
}
}
func (th TestHandler) UnsatisfiableRequest(action Action, missing AttributeDisjunctionList) {
th.c <- &Error{
th.c <- &SessionError{
ErrorCode: ErrorCode("UnsatisfiableRequest"),
}
}
......@@ -174,7 +174,7 @@ func sessionHelper(t *testing.T, jwtcontents interface{}, url string, manager *C
require.NoError(t, transportErr)
qr.URL = url + "/" + qr.URL
c := make(chan *Error)
c := make(chan *SessionError)
NewSession(manager, qr, TestHandler{t, c, manager})
if err := <-c; err != nil {
......
......@@ -57,7 +57,7 @@ func (transport *HTTPTransport) request(url string, method string, result interf
} else {
marshaled, err := json.Marshal(object)
if err != nil {
return &Error{Err: err, ErrorCode: ErrorSerialization}
return &SessionError{Err: err, ErrorCode: ErrorSerialization}
}
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 &Error{Err: err, ErrorCode: ErrorTransport}
return &SessionError{Err: err, ErrorCode: ErrorTransport}
}
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 &Error{ErrorCode: ErrorTransport, Err: err}
return &SessionError{ErrorCode: 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 &Error{ErrorCode: ErrorServerResponse, Err: err, Status: res.StatusCode}
return &SessionError{ErrorCode: ErrorServerResponse, Err: err, Status: res.StatusCode}
}
if res.StatusCode != 200 {
apierr := &ApiError{}
json.Unmarshal(body, apierr)
if apierr.ErrorName == "" { // Not an ApiErrorMessage
return &Error{ErrorCode: ErrorServerResponse, Status: res.StatusCode}
return &SessionError{ErrorCode: ErrorServerResponse, Status: res.StatusCode}
}
if verbose {
fmt.Printf("ERROR: %+v\n", apierr)
}
return &Error{ErrorCode: ErrorApi, Status: res.StatusCode, ApiError: apierr}
return &SessionError{ErrorCode: 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 &Error{ErrorCode: ErrorServerResponse, Err: err, Status: res.StatusCode}
return &SessionError{ErrorCode: 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