-
Notifications
You must be signed in to change notification settings - Fork 12
/
error.go
54 lines (46 loc) · 1.2 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package enigma
import (
"fmt"
"strings"
)
type (
// Error extends the built in error type with extra error information provided by the Qlik Associative Engine
Error interface {
error
Code() int
Parameter() string
Message() string
}
qixError struct {
ErrorCode int `json:"code"`
ErrorParameter string `json:"parameter"`
ErrorMessage string `json:"message"`
}
)
func (err *qixError) Error() string {
errorType := err.codeLookup()
return fmt.Sprintf("%s: %s (%d %s)", err.ErrorParameter, err.ErrorMessage, err.ErrorCode, errorType)
}
func (err *qixError) Code() int {
return err.ErrorCode
}
func (err *qixError) Parameter() string {
return err.ErrorParameter
}
func (err *qixError) Message() string {
return err.ErrorMessage
}
func (err *qixError) codeLookup() string {
errorType := ErrorCodeLookup(err.ErrorCode)
if len(errorType) < 7 {
// All error codes should result in a string prefixed with LOCERR_
// if the code is valid, so this is probably invalid.
// Just return whatever was returned by the lookup to be safe.
return errorType
}
if errorType[:7] == "LOCERR_" {
errorType = errorType[7:]
}
errorType = strings.Replace(errorType, "_", " ", -1)
return errorType
}