@@ -57,25 +57,33 @@ class ObjectBoxNativeError {
57
57
58
58
ObjectBoxNativeError (this .code, this .message, this .context);
59
59
60
- String get fullMessage =>
61
- context == null ? '$code $message ' : '$context : $code $message ' ;
60
+ String get messageWithContext =>
61
+ context == null ? message : '$context : $message ' ;
62
+
63
+ String get messageWithErrorCode => code == 0
64
+ ? messageWithContext
65
+ : '$messageWithContext (OBX_ERROR code $code )' ;
62
66
63
67
Never throwMapped () {
64
68
switch (code) {
65
69
case OBX_ERROR_ILLEGAL_STATE :
66
- throw StateError (fullMessage );
70
+ throw StateError (messageWithErrorCode );
67
71
case OBX_ERROR_ILLEGAL_ARGUMENT :
68
72
case OBX_ERROR_STD_ILLEGAL_ARGUMENT :
69
- throw ArgumentError (fullMessage );
73
+ throw ArgumentError (messageWithErrorCode );
70
74
case OBX_ERROR_NUMERIC_OVERFLOW :
71
75
case OBX_ERROR_STD_OUT_OF_RANGE :
72
76
case OBX_ERROR_STD_RANGE :
73
77
case OBX_ERROR_STD_OVERFLOW :
74
- throw RangeError (fullMessage );
78
+ throw RangeError (messageWithErrorCode );
75
79
case OBX_ERROR_UNIQUE_VIOLATED :
76
- throw UniqueViolationException (fullMessage );
80
+ throw UniqueViolationException (messageWithContext );
77
81
default :
78
- throw ObjectBoxException (fullMessage);
82
+ if (code == 0 ) {
83
+ throw ObjectBoxException (messageWithContext);
84
+ } else {
85
+ throw StorageException (messageWithContext, code);
86
+ }
79
87
}
80
88
}
81
89
}
0 commit comments