2023-07-05 18:48:06 -04:00
|
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
//////////////////////////////////////
|
|
|
|
/// VeilidAPIException
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
abstract class VeilidAPIException implements Exception {
|
|
|
|
factory VeilidAPIException.fromJson(dynamic json) {
|
2023-07-26 14:20:17 -04:00
|
|
|
switch (json['kind']) {
|
|
|
|
case 'NotInitialized':
|
2023-05-29 15:24:57 -04:00
|
|
|
{
|
|
|
|
return VeilidAPIExceptionNotInitialized();
|
|
|
|
}
|
2023-07-26 14:20:17 -04:00
|
|
|
case 'AlreadyInitialized':
|
2023-05-29 15:24:57 -04:00
|
|
|
{
|
|
|
|
return VeilidAPIExceptionAlreadyInitialized();
|
|
|
|
}
|
2023-07-26 14:20:17 -04:00
|
|
|
case 'Timeout':
|
2023-05-29 15:24:57 -04:00
|
|
|
{
|
|
|
|
return VeilidAPIExceptionTimeout();
|
|
|
|
}
|
2023-07-26 14:20:17 -04:00
|
|
|
case 'TryAgain':
|
2023-05-29 15:24:57 -04:00
|
|
|
{
|
|
|
|
return VeilidAPIExceptionTryAgain();
|
|
|
|
}
|
2023-07-26 14:20:17 -04:00
|
|
|
case 'Shutdown':
|
2023-05-29 15:24:57 -04:00
|
|
|
{
|
|
|
|
return VeilidAPIExceptionShutdown();
|
|
|
|
}
|
2023-07-26 14:20:17 -04:00
|
|
|
case 'InvalidTarget':
|
2023-05-29 15:24:57 -04:00
|
|
|
{
|
|
|
|
return VeilidAPIExceptionInvalidTarget();
|
|
|
|
}
|
2023-07-26 14:20:17 -04:00
|
|
|
case 'NoConnection':
|
2023-05-29 15:24:57 -04:00
|
|
|
{
|
2023-07-26 14:20:17 -04:00
|
|
|
return VeilidAPIExceptionNoConnection(json['message']);
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
2023-07-26 14:20:17 -04:00
|
|
|
case 'KeyNotFound':
|
2023-05-29 15:24:57 -04:00
|
|
|
{
|
2023-07-26 14:20:17 -04:00
|
|
|
return VeilidAPIExceptionKeyNotFound(json['key']);
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
2023-07-26 14:20:17 -04:00
|
|
|
case 'Internal':
|
2023-05-29 15:24:57 -04:00
|
|
|
{
|
2023-07-26 14:20:17 -04:00
|
|
|
return VeilidAPIExceptionInternal(json['message']);
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
2023-07-26 14:20:17 -04:00
|
|
|
case 'Unimplemented':
|
2023-05-29 15:24:57 -04:00
|
|
|
{
|
2023-07-26 14:20:17 -04:00
|
|
|
return VeilidAPIExceptionUnimplemented(json['unimplemented']);
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
2023-07-26 14:20:17 -04:00
|
|
|
case 'ParseError':
|
2023-05-29 15:24:57 -04:00
|
|
|
{
|
2023-07-26 14:20:17 -04:00
|
|
|
return VeilidAPIExceptionParseError(json['message'], json['value']);
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
2023-07-26 14:20:17 -04:00
|
|
|
case 'InvalidArgument':
|
2023-05-29 15:24:57 -04:00
|
|
|
{
|
|
|
|
return VeilidAPIExceptionInvalidArgument(
|
2023-07-26 14:20:17 -04:00
|
|
|
json['context'], json['argument'], json['value']);
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
2023-07-26 14:20:17 -04:00
|
|
|
case 'MissingArgument':
|
2023-05-29 15:24:57 -04:00
|
|
|
{
|
|
|
|
return VeilidAPIExceptionMissingArgument(
|
2023-07-26 14:20:17 -04:00
|
|
|
json['context'], json['argument']);
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
2023-07-26 14:20:17 -04:00
|
|
|
case 'Generic':
|
2023-05-29 15:24:57 -04:00
|
|
|
{
|
2023-07-26 14:20:17 -04:00
|
|
|
return VeilidAPIExceptionGeneric(json['message']);
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
throw VeilidAPIExceptionInternal(
|
|
|
|
"Invalid VeilidAPIException type: ${json['kind']}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String toDisplayError();
|
|
|
|
}
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
class VeilidAPIExceptionNotInitialized implements VeilidAPIException {
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toString() => 'VeilidAPIException: NotInitialized';
|
2023-05-29 15:24:57 -04:00
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toDisplayError() => 'Not initialized';
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
class VeilidAPIExceptionAlreadyInitialized implements VeilidAPIException {
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toString() => 'VeilidAPIException: AlreadyInitialized';
|
2023-05-29 15:24:57 -04:00
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toDisplayError() => 'Already initialized';
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
class VeilidAPIExceptionTimeout implements VeilidAPIException {
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toString() => 'VeilidAPIException: Timeout';
|
2023-05-29 15:24:57 -04:00
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toDisplayError() => 'Timeout';
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
class VeilidAPIExceptionTryAgain implements VeilidAPIException {
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toString() => 'VeilidAPIException: TryAgain';
|
2023-05-29 15:24:57 -04:00
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toDisplayError() => 'Try again';
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
class VeilidAPIExceptionShutdown implements VeilidAPIException {
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toString() => 'VeilidAPIException: Shutdown';
|
2023-05-29 15:24:57 -04:00
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toDisplayError() => 'Currently shut down';
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
class VeilidAPIExceptionInvalidTarget implements VeilidAPIException {
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toString() => 'VeilidAPIException: InvalidTarget';
|
2023-05-29 15:24:57 -04:00
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toDisplayError() => 'Invalid target';
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
class VeilidAPIExceptionNoConnection implements VeilidAPIException {
|
2023-07-26 14:20:17 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
const VeilidAPIExceptionNoConnection(this.message);
|
2023-05-29 15:24:57 -04:00
|
|
|
final String message;
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toString() => 'VeilidAPIException: NoConnection (message: $message)';
|
2023-05-29 15:24:57 -04:00
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toDisplayError() => 'No connection: $message';
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
class VeilidAPIExceptionKeyNotFound implements VeilidAPIException {
|
2023-07-26 14:20:17 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
const VeilidAPIExceptionKeyNotFound(this.key);
|
2023-05-29 15:24:57 -04:00
|
|
|
final String key;
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toString() => 'VeilidAPIException: KeyNotFound (key: $key)';
|
2023-05-29 15:24:57 -04:00
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toDisplayError() => 'Key not found: $key';
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
class VeilidAPIExceptionInternal implements VeilidAPIException {
|
2023-07-26 14:20:17 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
const VeilidAPIExceptionInternal(this.message);
|
2023-05-29 15:24:57 -04:00
|
|
|
final String message;
|
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toString() => 'VeilidAPIException: Internal ($message)';
|
2023-05-29 15:24:57 -04:00
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toDisplayError() => 'Internal error: $message';
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
class VeilidAPIExceptionUnimplemented implements VeilidAPIException {
|
2023-07-26 14:20:17 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
const VeilidAPIExceptionUnimplemented(this.message);
|
2023-05-29 15:24:57 -04:00
|
|
|
final String message;
|
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toString() => 'VeilidAPIException: Unimplemented ($message)';
|
2023-05-29 15:24:57 -04:00
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toDisplayError() => 'Unimplemented: $message';
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
class VeilidAPIExceptionParseError implements VeilidAPIException {
|
2023-07-26 14:20:17 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
const VeilidAPIExceptionParseError(this.message, this.value);
|
2023-05-29 15:24:57 -04:00
|
|
|
final String message;
|
|
|
|
final String value;
|
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toString() => 'VeilidAPIException: ParseError ($message)\n value: $value';
|
2023-05-29 15:24:57 -04:00
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toDisplayError() => 'Parse error: $message';
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
class VeilidAPIExceptionInvalidArgument implements VeilidAPIException {
|
2023-07-26 14:20:17 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
const VeilidAPIExceptionInvalidArgument(
|
|
|
|
this.context, this.argument, this.value);
|
2023-05-29 15:24:57 -04:00
|
|
|
final String context;
|
|
|
|
final String argument;
|
|
|
|
final String value;
|
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toString() => 'VeilidAPIException: InvalidArgument ($context:$argument)\n value: $value';
|
2023-05-29 15:24:57 -04:00
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toDisplayError() => 'Invalid argument for $context: $argument';
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
class VeilidAPIExceptionMissingArgument implements VeilidAPIException {
|
2023-07-26 14:20:17 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
const VeilidAPIExceptionMissingArgument(this.context, this.argument);
|
2023-05-29 15:24:57 -04:00
|
|
|
final String context;
|
|
|
|
final String argument;
|
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toString() => 'VeilidAPIException: MissingArgument ($context:$argument)';
|
2023-05-29 15:24:57 -04:00
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toDisplayError() => 'Missing argument for $context: $argument';
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|
|
|
|
|
2023-07-05 18:48:06 -04:00
|
|
|
@immutable
|
2023-05-29 15:24:57 -04:00
|
|
|
class VeilidAPIExceptionGeneric implements VeilidAPIException {
|
2023-07-26 14:20:17 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
const VeilidAPIExceptionGeneric(this.message);
|
2023-05-29 15:24:57 -04:00
|
|
|
final String message;
|
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toString() => 'VeilidAPIException: Generic (message: $message)';
|
2023-05-29 15:24:57 -04:00
|
|
|
|
|
|
|
@override
|
2023-07-26 14:20:17 -04:00
|
|
|
String toDisplayError() => message;
|
2023-05-29 15:24:57 -04:00
|
|
|
}
|