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,
|
||||
Emitter<OrganizationState> emit,
|
||||
) 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();
|
||||
if (name.isEmpty) {
|
||||
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 {
|
||||
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];
|
||||
emit(OrganizationLoaded(organizations: updatedOrgs, selectedOrg: newOrg));
|
||||
// Reset blocs and load permissions for new org
|
||||
|
||||
@@ -13,7 +13,9 @@ class ApiClient {
|
||||
BaseOptions(
|
||||
baseUrl: baseUrl,
|
||||
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,
|
||||
required T Function(dynamic data) fromJson,
|
||||
}) async {
|
||||
print('[DEBUG-API-CLIENT] POST request starting - path: $path, data: $data');
|
||||
print(
|
||||
'[DEBUG-API-CLIENT] POST request starting - path: $path, data: $data',
|
||||
);
|
||||
try {
|
||||
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);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,16 +15,20 @@ class OrgApi {
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
|
||||
try {
|
||||
final result = await _apiClient.post(
|
||||
'/orgs',
|
||||
data: {'name': name},
|
||||
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;
|
||||
} catch (e) {
|
||||
print('[DEBUG-ORG-CREATION] OrgApi.createOrganization error: $e');
|
||||
|
||||
Reference in New Issue
Block a user