Refactor debug logging for organization creation and API client methods
This commit is contained in:
@@ -97,7 +97,9 @@ class OrganizationBloc extends Bloc<OrganizationEvent, OrganizationState> {
|
|||||||
CreateOrganization event,
|
CreateOrganization event,
|
||||||
Emitter<OrganizationState> emit,
|
Emitter<OrganizationState> emit,
|
||||||
) async {
|
) async {
|
||||||
print('[DEBUG-ORG-CREATION] CreateOrganization event received with name: "${event.name}"');
|
print(
|
||||||
|
'[DEBUG-ORG-CREATION] CreateOrganization event received with name: "${event.name}"',
|
||||||
|
);
|
||||||
final name = event.name.trim();
|
final name = event.name.trim();
|
||||||
if (name.isEmpty) {
|
if (name.isEmpty) {
|
||||||
print('[DEBUG-ORG-CREATION] Name is empty after trim');
|
print('[DEBUG-ORG-CREATION] Name is empty after trim');
|
||||||
@@ -146,10 +148,14 @@ class OrganizationBloc extends Bloc<OrganizationEvent, OrganizationState> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
print('[DEBUG-ORG-CREATION] About to call orgApi.createOrganization with name: "$name"');
|
print(
|
||||||
|
'[DEBUG-ORG-CREATION] About to call orgApi.createOrganization with name: "$name"',
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
final newOrg = await orgApi.createOrganization(name);
|
final newOrg = await orgApi.createOrganization(name);
|
||||||
print('[DEBUG-ORG-CREATION] API returned successfully: ${newOrg.id} - ${newOrg.name}');
|
print(
|
||||||
|
'[DEBUG-ORG-CREATION] API returned successfully: ${newOrg.id} - ${newOrg.name}',
|
||||||
|
);
|
||||||
final updatedOrgs = [...existingOrgs, newOrg];
|
final updatedOrgs = [...existingOrgs, newOrg];
|
||||||
emit(OrganizationLoaded(organizations: updatedOrgs, selectedOrg: newOrg));
|
emit(OrganizationLoaded(organizations: updatedOrgs, selectedOrg: newOrg));
|
||||||
// Reset blocs and load permissions for new org
|
// Reset blocs and load permissions for new org
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ class ApiClient {
|
|||||||
BaseOptions(
|
BaseOptions(
|
||||||
baseUrl: baseUrl,
|
baseUrl: baseUrl,
|
||||||
connectTimeout: const Duration(seconds: 10),
|
connectTimeout: const Duration(seconds: 10),
|
||||||
receiveTimeout: const Duration(seconds: 60), // Increased for file uploads and org operations
|
receiveTimeout: const Duration(
|
||||||
|
seconds: 60,
|
||||||
|
), // Increased for file uploads and org operations
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -72,13 +74,19 @@ class ApiClient {
|
|||||||
dynamic data,
|
dynamic data,
|
||||||
required T Function(dynamic data) fromJson,
|
required T Function(dynamic data) fromJson,
|
||||||
}) async {
|
}) async {
|
||||||
print('[DEBUG-API-CLIENT] POST request starting - path: $path, data: $data');
|
print(
|
||||||
|
'[DEBUG-API-CLIENT] POST request starting - path: $path, data: $data',
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
final response = await _dio.post(path, data: data);
|
final response = await _dio.post(path, data: data);
|
||||||
print('[DEBUG-API-CLIENT] POST response received - status: ${response.statusCode}, data: ${response.data}');
|
print(
|
||||||
|
'[DEBUG-API-CLIENT] POST response received - status: ${response.statusCode}, data: ${response.data}',
|
||||||
|
);
|
||||||
return fromJson(response.data);
|
return fromJson(response.data);
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
print('[DEBUG-API-CLIENT] POST request failed - type: ${e.type}, message: ${e.message}, status: ${e.response?.statusCode}');
|
print(
|
||||||
|
'[DEBUG-API-CLIENT] POST request failed - type: ${e.type}, message: ${e.message}, status: ${e.response?.statusCode}',
|
||||||
|
);
|
||||||
throw _handleError(e);
|
throw _handleError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ class OrgApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Organization> createOrganization(String name) async {
|
Future<Organization> createOrganization(String name) async {
|
||||||
print('[DEBUG-ORG-CREATION] OrgApi.createOrganization called with name: "$name"');
|
print(
|
||||||
|
'[DEBUG-ORG-CREATION] OrgApi.createOrganization called with name: "$name"',
|
||||||
|
);
|
||||||
developer.log('POST /orgs with payload: {"name": "$name"}', name: 'OrgApi');
|
developer.log('POST /orgs with payload: {"name": "$name"}', name: 'OrgApi');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -24,7 +26,9 @@ class OrgApi {
|
|||||||
data: {'name': name},
|
data: {'name': name},
|
||||||
fromJson: (data) => Organization.fromJson(data),
|
fromJson: (data) => Organization.fromJson(data),
|
||||||
);
|
);
|
||||||
print('[DEBUG-ORG-CREATION] OrgApi.createOrganization returned: ${result.id}');
|
print(
|
||||||
|
'[DEBUG-ORG-CREATION] OrgApi.createOrganization returned: ${result.id}',
|
||||||
|
);
|
||||||
return result;
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('[DEBUG-ORG-CREATION] OrgApi.createOrganization error: $e');
|
print('[DEBUG-ORG-CREATION] OrgApi.createOrganization error: $e');
|
||||||
|
|||||||
Reference in New Issue
Block a user