Browse Source

fix: improve error handling in photo upload

- Add proper unknown type for error handling in PhotoDialog
- Remove any type in favor of unknown for better type safety
- Fix error message access with type guards
cross-platform-factory
Matthew Raymer 3 weeks ago
parent
commit
660f2170de
  1. 3
      .eslintrc.js
  2. 8
      src/components/PhotoDialog.vue
  3. 1
      src/services/PlatformServiceFactory.ts
  4. 4
      src/services/platforms/CapacitorPlatformService.ts
  5. 10
      src/services/platforms/ElectronPlatformService.ts
  6. 10
      src/services/platforms/PyWebViewPlatformService.ts
  7. 10
      src/services/platforms/WebPlatformService.ts

3
.eslintrc.js

@ -26,6 +26,7 @@ module.exports = {
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "warn", "no-debugger": process.env.NODE_ENV === "production" ? "error" : "warn",
"@typescript-eslint/no-explicit-any": "warn", "@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-unnecessary-type-constraint": "off" "@typescript-eslint/no-unnecessary-type-constraint": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
}, },
}; };

8
src/components/PhotoDialog.vue

@ -130,7 +130,7 @@ export default class PhotoDialog extends Vue {
try { try {
const settings = await retrieveSettingsForActiveAccount(); const settings = await retrieveSettingsForActiveAccount();
this.activeDid = settings.activeDid || ""; this.activeDid = settings.activeDid || "";
} catch (err: any) { } catch (err: unknown) {
logger.error("Error retrieving settings from database:", err); logger.error("Error retrieving settings from database:", err);
this.$notify( this.$notify(
{ {
@ -184,7 +184,7 @@ export default class PhotoDialog extends Vue {
const result = await this.platformService.takePicture(); const result = await this.platformService.takePicture();
this.blob = result.blob; this.blob = result.blob;
this.fileName = result.fileName; this.fileName = result.fileName;
} catch (error) { } catch (error: unknown) {
logger.error("Error taking picture:", error); logger.error("Error taking picture:", error);
this.$notify( this.$notify(
{ {
@ -203,7 +203,7 @@ export default class PhotoDialog extends Vue {
const result = await this.platformService.pickImage(); const result = await this.platformService.pickImage();
this.blob = result.blob; this.blob = result.blob;
this.fileName = result.fileName; this.fileName = result.fileName;
} catch (error) { } catch (error: unknown) {
logger.error("Error picking image:", error); logger.error("Error picking image:", error);
this.$notify( this.$notify(
{ {
@ -270,7 +270,7 @@ export default class PhotoDialog extends Vue {
this.close(); this.close();
this.setImageCallback(response.data.url as string); this.setImageCallback(response.data.url as string);
} catch (error) { } catch (error: unknown) {
// Log the raw error first // Log the raw error first
logger.error("Raw error object:", JSON.stringify(error, null, 2)); logger.error("Raw error object:", JSON.stringify(error, null, 2));

1
src/services/PlatformServiceFactory.ts

@ -1,4 +1,3 @@
import { Capacitor } from "@capacitor/core";
import { PlatformService } from "./PlatformService"; import { PlatformService } from "./PlatformService";
import { WebPlatformService } from "./platforms/WebPlatformService"; import { WebPlatformService } from "./platforms/WebPlatformService";
import { CapacitorPlatformService } from "./platforms/CapacitorPlatformService"; import { CapacitorPlatformService } from "./platforms/CapacitorPlatformService";

4
src/services/platforms/CapacitorPlatformService.ts

@ -1,8 +1,6 @@
import { ImageResult, PlatformService } from "../PlatformService"; import { ImageResult, PlatformService } from "../PlatformService";
import { Capacitor } from "@capacitor/core";
import { Filesystem, Directory } from "@capacitor/filesystem"; import { Filesystem, Directory } from "@capacitor/filesystem";
import { Camera, CameraResultType, CameraSource } from "@capacitor/camera"; import { Camera, CameraResultType, CameraSource } from "@capacitor/camera";
import { App } from "@capacitor/app";
import { logger } from "../../utils/logger"; import { logger } from "../../utils/logger";
export class CapacitorPlatformService implements PlatformService { export class CapacitorPlatformService implements PlatformService {
@ -113,7 +111,7 @@ export class CapacitorPlatformService implements PlatformService {
return false; return false;
} }
async handleDeepLink(url: string): Promise<void> { async handleDeepLink(_url: string): Promise<void> {
// Capacitor handles deep links automatically // Capacitor handles deep links automatically
// This is just a placeholder for the interface // This is just a placeholder for the interface
return Promise.resolve(); return Promise.resolve();

10
src/services/platforms/ElectronPlatformService.ts

@ -2,19 +2,19 @@ import { ImageResult, PlatformService } from "../PlatformService";
import { logger } from "../../utils/logger"; import { logger } from "../../utils/logger";
export class ElectronPlatformService implements PlatformService { export class ElectronPlatformService implements PlatformService {
async readFile(path: string): Promise<string> { async readFile(_path: string): Promise<string> {
throw new Error("Not implemented"); throw new Error("Not implemented");
} }
async writeFile(path: string, content: string): Promise<void> { async writeFile(_path: string, _content: string): Promise<void> {
throw new Error("Not implemented"); throw new Error("Not implemented");
} }
async deleteFile(path: string): Promise<void> { async deleteFile(_path: string): Promise<void> {
throw new Error("Not implemented"); throw new Error("Not implemented");
} }
async listFiles(directory: string): Promise<string[]> { async listFiles(_directory: string): Promise<string[]> {
throw new Error("Not implemented"); throw new Error("Not implemented");
} }
@ -44,7 +44,7 @@ export class ElectronPlatformService implements PlatformService {
return false; return false;
} }
async handleDeepLink(url: string): Promise<void> { async handleDeepLink(_url: string): Promise<void> {
logger.error("handleDeepLink not implemented in Electron platform"); logger.error("handleDeepLink not implemented in Electron platform");
throw new Error("Not implemented"); throw new Error("Not implemented");
} }

10
src/services/platforms/PyWebViewPlatformService.ts

@ -2,19 +2,19 @@ import { ImageResult, PlatformService } from "../PlatformService";
import { logger } from "../../utils/logger"; import { logger } from "../../utils/logger";
export class PyWebViewPlatformService implements PlatformService { export class PyWebViewPlatformService implements PlatformService {
async readFile(path: string): Promise<string> { async readFile(_path: string): Promise<string> {
throw new Error("Not implemented"); throw new Error("Not implemented");
} }
async writeFile(path: string, content: string): Promise<void> { async writeFile(_path: string, _content: string): Promise<void> {
throw new Error("Not implemented"); throw new Error("Not implemented");
} }
async deleteFile(path: string): Promise<void> { async deleteFile(_path: string): Promise<void> {
throw new Error("Not implemented"); throw new Error("Not implemented");
} }
async listFiles(directory: string): Promise<string[]> { async listFiles(_directory: string): Promise<string[]> {
throw new Error("Not implemented"); throw new Error("Not implemented");
} }
@ -44,7 +44,7 @@ export class PyWebViewPlatformService implements PlatformService {
return false; return false;
} }
async handleDeepLink(url: string): Promise<void> { async handleDeepLink(_url: string): Promise<void> {
logger.error("handleDeepLink not implemented in PyWebView platform"); logger.error("handleDeepLink not implemented in PyWebView platform");
throw new Error("Not implemented"); throw new Error("Not implemented");
} }

10
src/services/platforms/WebPlatformService.ts

@ -2,19 +2,19 @@ import { ImageResult, PlatformService } from "../PlatformService";
import { logger } from "../../utils/logger"; import { logger } from "../../utils/logger";
export class WebPlatformService implements PlatformService { export class WebPlatformService implements PlatformService {
async readFile(path: string): Promise<string> { async readFile(_path: string): Promise<string> {
throw new Error("File system access not available in web platform"); throw new Error("File system access not available in web platform");
} }
async writeFile(path: string, content: string): Promise<void> { async writeFile(_path: string, _content: string): Promise<void> {
throw new Error("File system access not available in web platform"); throw new Error("File system access not available in web platform");
} }
async deleteFile(path: string): Promise<void> { async deleteFile(_path: string): Promise<void> {
throw new Error("File system access not available in web platform"); throw new Error("File system access not available in web platform");
} }
async listFiles(directory: string): Promise<string[]> { async listFiles(_directory: string): Promise<string[]> {
throw new Error("File system access not available in web platform"); throw new Error("File system access not available in web platform");
} }
@ -113,7 +113,7 @@ export class WebPlatformService implements PlatformService {
return true; return true;
} }
async handleDeepLink(url: string): Promise<void> { async handleDeepLink(_url: string): Promise<void> {
// Web platform can handle deep links through URL parameters // Web platform can handle deep links through URL parameters
return Promise.resolve(); return Promise.resolve();
} }

Loading…
Cancel
Save