fix(types): resolve TypeScript any type violations
- Replace any types in ProfileService with AxiosErrorResponse interface - Add type-safe error URL extraction method - Fix Leaflet icon type assertion using Record<string, unknown> - Enhance AxiosErrorResponse interface with missing properties - Maintain existing functionality while improving type safety Closes typing violations in ProfileService.ts and AccountViewView.vue
This commit is contained in:
@@ -10,6 +10,7 @@ import { getHeaders, errorStringForLog } from "@/libs/endorserServer";
|
||||
import { handleApiError } from "./api";
|
||||
import { logger } from "@/utils/logger";
|
||||
import { ACCOUNT_VIEW_CONSTANTS } from "@/constants/accountView";
|
||||
import { AxiosErrorResponse } from "@/interfaces/common";
|
||||
|
||||
/**
|
||||
* Profile data interface
|
||||
@@ -124,36 +125,29 @@ export class ProfileService {
|
||||
async deleteProfile(activeDid: string): Promise<boolean> {
|
||||
try {
|
||||
const headers = await getHeaders(activeDid);
|
||||
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 });
|
||||
const response = await this.axios.delete(
|
||||
`${this.partnerApiServer}/api/partner/userProfile`,
|
||||
{ headers },
|
||||
);
|
||||
|
||||
if (response.status === 200 || response.status === 204) {
|
||||
logger.debug("Profile deleted successfully");
|
||||
if (response.status === 204 || response.status === 200) {
|
||||
logger.info("Profile deleted successfully");
|
||||
return true;
|
||||
} else {
|
||||
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}`);
|
||||
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
|
||||
const response = error.response;
|
||||
logger.error("API error deleting profile:", {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
data: response.data,
|
||||
url: (error as any).config?.url
|
||||
url: this.getErrorUrl(error),
|
||||
});
|
||||
|
||||
|
||||
// Handle specific HTTP status codes
|
||||
if (response.status === 204) {
|
||||
logger.debug("Profile deleted successfully (204 No Content)");
|
||||
@@ -163,7 +157,9 @@ export class ProfileService {
|
||||
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'}`);
|
||||
throw new Error(
|
||||
`Profile deletion failed: ${response.data?.error?.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");
|
||||
@@ -172,7 +168,7 @@ export class ProfileService {
|
||||
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;
|
||||
@@ -242,13 +238,22 @@ export class ProfileService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard for API errors
|
||||
* Type guard for API errors with proper typing
|
||||
*/
|
||||
private isApiError(
|
||||
error: unknown,
|
||||
): error is { response?: { status?: number } } {
|
||||
private isApiError(error: unknown): error is AxiosErrorResponse {
|
||||
return typeof error === "object" && error !== null && "response" in error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract error URL safely from error object
|
||||
*/
|
||||
private getErrorUrl(error: unknown): string | undefined {
|
||||
if (this.isApiError(error) && error.config) {
|
||||
const config = error.config as { url?: string };
|
||||
return config.url;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user