Commit cd6a1f63 authored by Tomas's avatar Tomas
Browse files

ApiError -> RemoteError

parent bc84be70
......@@ -218,12 +218,12 @@ func startKeyshareSession(
func (ks *keyshareSession) fail(manager irma.SchemeManagerIdentifier, err error) {
serr, ok := err.(*irma.SessionError)
if ok {
if serr.ApiError != nil && len(serr.ApiError.ErrorName) > 0 {
switch serr.ApiError.ErrorName {
if serr.RemoteError != nil && len(serr.RemoteError.ErrorName) > 0 {
switch serr.RemoteError.ErrorName {
case "USER_NOT_REGISTERED":
ks.sessionHandler.KeyshareEnrollmentIncomplete(manager)
case "USER_BLOCKED":
duration, err := strconv.Atoi(serr.ApiError.Message)
duration, err := strconv.Atoi(serr.RemoteError.Message)
if err != nil { // Not really clear what to do with duration, but should never happen anyway
duration = -1
}
......
......@@ -48,14 +48,13 @@ type ErrorType string
type SessionError struct {
Err error
ErrorType
*ApiError
Info string
Status int
StatusMessage string
Info string
RemoteError *RemoteError
RemoteStatus int
}
// ApiError is an error message returned by the API server on errors.
type ApiError struct {
// RemoteError is an error message returned by the API server on errors.
type RemoteError struct {
Status int `json:"status"`
ErrorName string `json:"error"`
Description string `json:"description"`
......@@ -63,7 +62,7 @@ type ApiError struct {
Stacktrace string `json:"stacktrace"`
}
func (err *ApiError) Error() string {
func (err *RemoteError) Error() string {
var msg string
if err.Message != "" {
msg = fmt.Sprintf(" (%s)", err.Message)
......@@ -154,13 +153,13 @@ func (e *SessionError) Error() string {
buffer.WriteString("\nDescription: ")
buffer.WriteString(e.Err.Error())
}
if e.Status != 200 && e.StatusMessage != "" {
buffer.WriteString("\nConnection: ")
buffer.WriteString(e.StatusMessage)
if e.RemoteStatus != 200 {
buffer.WriteString("\nStatus code: ")
buffer.WriteString(string(e.RemoteStatus))
}
if e.ApiError != nil {
if e.RemoteError != nil {
buffer.WriteString("\nIRMA server error: ")
buffer.WriteString(e.ApiError.Error())
buffer.WriteString(e.RemoteError.Error())
}
return buffer.String()
......
......@@ -128,18 +128,18 @@ func (transport *HTTPTransport) jsonRequest(url string, method string, result in
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return &SessionError{ErrorType: ErrorServerResponse, Err: err, Status: res.StatusCode, StatusMessage: res.Status}
return &SessionError{ErrorType: ErrorServerResponse, Err: err, RemoteStatus: res.StatusCode}
}
if res.StatusCode != 200 {
apierr := &ApiError{}
apierr := &RemoteError{}
err = json.Unmarshal(body, apierr)
if err != nil || apierr.ErrorName == "" { // Not an ApiErrorMessage
return &SessionError{ErrorType: ErrorServerResponse, Status: res.StatusCode, StatusMessage: res.Status}
return &SessionError{ErrorType: ErrorServerResponse, RemoteStatus: res.StatusCode}
}
if verbose {
fmt.Printf("ERROR: %+v\n", apierr)
}
return &SessionError{ErrorType: ErrorApi, Status: res.StatusCode, ApiError: apierr, StatusMessage: res.Status}
return &SessionError{ErrorType: ErrorApi, RemoteStatus: res.StatusCode, RemoteError: apierr}
}
if verbose {
......@@ -150,7 +150,7 @@ func (transport *HTTPTransport) jsonRequest(url string, method string, result in
} else {
err = json.Unmarshal(body, result)
if err != nil {
return &SessionError{ErrorType: ErrorServerResponse, Err: err, Status: res.StatusCode, StatusMessage: res.Status}
return &SessionError{ErrorType: ErrorServerResponse, Err: err, RemoteStatus: res.StatusCode}
}
}
......@@ -164,11 +164,11 @@ func (transport *HTTPTransport) GetBytes(url string) ([]byte, error) {
}
if res.StatusCode != 200 {
return nil, &SessionError{ErrorType: ErrorServerResponse, Status: res.StatusCode}
return nil, &SessionError{ErrorType: ErrorServerResponse, RemoteStatus: res.StatusCode}
}
b, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, &SessionError{ErrorType: ErrorServerResponse, Err: err, Status: res.StatusCode, StatusMessage: res.Status}
return nil, &SessionError{ErrorType: ErrorServerResponse, Err: err, RemoteStatus: res.StatusCode}
}
return b, nil
}
......
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