fix(profile): resolve map loading and profile deletion issues
- Fix Leaflet icon initialization error causing "Cannot read properties of undefined (reading 'Default')" - Add proper Leaflet icon configuration with CDN fallbacks - Implement map ready state management to prevent infinite loading - Add comprehensive error handling and debugging for map lifecycle events - Fix profile deletion treating HTTP 204 (No Content) as error instead of success - Enhance error logging and user feedback throughout profile operations - Add fallback timeout mechanisms for map initialization failures - Improve error messages to show specific API failure reasons Resolves map rendering issues and profile deletion failures by properly handling HTTP status codes and Leaflet component initialization.
This commit is contained in:
@@ -124,17 +124,55 @@ export class ProfileService {
|
||||
async deleteProfile(activeDid: string): Promise<boolean> {
|
||||
try {
|
||||
const headers = await getHeaders(activeDid);
|
||||
const response = await this.axios.delete(
|
||||
`${this.partnerApiServer}/api/partner/userProfile`,
|
||||
{ headers },
|
||||
);
|
||||
logger.debug("Attempting to delete profile for DID:", activeDid);
|
||||
logger.debug("Using partner API server:", this.partnerApiServer);
|
||||
logger.debug("Request headers:", headers);
|
||||
|
||||
const url = `${this.partnerApiServer}/api/partner/userProfile`;
|
||||
logger.debug("DELETE request URL:", url);
|
||||
|
||||
const response = await this.axios.delete(url, { headers });
|
||||
|
||||
if (response.status === 200) {
|
||||
if (response.status === 200 || response.status === 204) {
|
||||
logger.debug("Profile deleted successfully");
|
||||
return true;
|
||||
} else {
|
||||
throw new Error(ACCOUNT_VIEW_CONSTANTS.ERRORS.PROFILE_NOT_DELETED);
|
||||
logger.error("Unexpected response status when deleting profile:", {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
data: response.data
|
||||
});
|
||||
throw new Error(`Profile not deleted - HTTP ${response.status}: ${response.statusText}`);
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.isApiError(error) && error.response) {
|
||||
const response = error.response as any; // Type assertion for error response
|
||||
logger.error("API error deleting profile:", {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
data: response.data,
|
||||
url: (error as any).config?.url
|
||||
});
|
||||
|
||||
// Handle specific HTTP status codes
|
||||
if (response.status === 204) {
|
||||
logger.debug("Profile deleted successfully (204 No Content)");
|
||||
return true; // 204 is success for DELETE operations
|
||||
} else if (response.status === 404) {
|
||||
logger.warn("Profile not found - may already be deleted");
|
||||
return true; // Consider this a success if profile doesn't exist
|
||||
} else if (response.status === 400) {
|
||||
logger.error("Bad request when deleting profile:", response.data);
|
||||
throw new Error(`Profile deletion failed: ${response.data?.message || 'Bad request'}`);
|
||||
} else if (response.status === 401) {
|
||||
logger.error("Unauthorized to delete profile");
|
||||
throw new Error("You are not authorized to delete this profile");
|
||||
} else if (response.status === 403) {
|
||||
logger.error("Forbidden to delete profile");
|
||||
throw new Error("You are not allowed to delete this profile");
|
||||
}
|
||||
}
|
||||
|
||||
logger.error("Error deleting profile:", errorStringForLog(error));
|
||||
handleApiError(error as AxiosError, "/api/partner/userProfile");
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user