Skip to content

Commit e8ec643

Browse files
authored
fix: throw correct error code for unimplemented methods (#316)
1 parent e39ac78 commit e8ec643

File tree

9 files changed

+54
-30
lines changed

9 files changed

+54
-30
lines changed

.changeset/huge-monkeys-return.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@capacitor-mlkit/face-mesh-detection': major
3+
'@capacitor-mlkit/selfie-segmentation': major
4+
'@capacitor-mlkit/barcode-scanning': major
5+
'@capacitor-mlkit/face-detection': major
6+
---
7+
8+
fix: throw correct error code for unimplemented methods

packages/barcode-scanning/BREAKING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ This is a comprehensive list of the breaking changes introduced in the major ver
1515

1616
This plugin now supports **Capacitor 8**. The minimum Android SDK version is **36**. Ensure your project meets these requirements before upgrading.
1717

18+
### Error codes
19+
20+
On **Web**, unimplemented methods now throw an error with code `Unimplemented` instead of `Unavailable`.
21+
1822
### Variables
1923

2024
- On Android, the `androidxCameraCamera2Version` variable has been updated to `1.5.2`.

packages/barcode-scanning/src/web.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class BarcodeScannerWeb
4040

4141
async startScan(options?: StartScanOptions): Promise<void> {
4242
if (!this._isSupported) {
43-
throw this.createUnavailableException();
43+
throw this.createUnimplementedException();
4444
}
4545
if (!options?.videoElement) {
4646
throw new Error(this.errorVideoElementMissing);
@@ -73,7 +73,7 @@ export class BarcodeScannerWeb
7373

7474
async stopScan(): Promise<void> {
7575
if (!this._isSupported) {
76-
throw this.createUnavailableException();
76+
throw this.createUnimplementedException();
7777
}
7878
if (this.intervalId) {
7979
clearInterval(this.intervalId);
@@ -92,63 +92,63 @@ export class BarcodeScannerWeb
9292
async readBarcodesFromImage(
9393
_options: ReadBarcodesFromImageOptions,
9494
): Promise<ReadBarcodesFromImageResult> {
95-
throw this.createUnavailableException();
95+
throw this.createUnimplementedException();
9696
}
9797

9898
async scan(): Promise<ScanResult> {
99-
throw this.createUnavailableException();
99+
throw this.createUnimplementedException();
100100
}
101101

102102
async isSupported(): Promise<IsSupportedResult> {
103103
return { supported: this._isSupported };
104104
}
105105

106106
async enableTorch(): Promise<void> {
107-
throw this.createUnavailableException();
107+
throw this.createUnimplementedException();
108108
}
109109

110110
async disableTorch(): Promise<void> {
111-
throw this.createUnavailableException();
111+
throw this.createUnimplementedException();
112112
}
113113

114114
async toggleTorch(): Promise<void> {
115-
throw this.createUnavailableException();
115+
throw this.createUnimplementedException();
116116
}
117117

118118
async isTorchEnabled(): Promise<IsTorchEnabledResult> {
119-
throw this.createUnavailableException;
119+
throw this.createUnimplementedException();
120120
}
121121

122122
async isTorchAvailable(): Promise<IsTorchAvailableResult> {
123123
return { available: false };
124124
}
125125

126126
async setZoomRatio(_options: SetZoomRatioOptions): Promise<void> {
127-
throw this.createUnavailableException();
127+
throw this.createUnimplementedException();
128128
}
129129

130130
async getZoomRatio(): Promise<GetZoomRatioResult> {
131-
throw this.createUnavailableException();
131+
throw this.createUnimplementedException();
132132
}
133133

134134
async getMinZoomRatio(): Promise<GetMinZoomRatioResult> {
135-
throw this.createUnavailableException();
135+
throw this.createUnimplementedException();
136136
}
137137

138138
async getMaxZoomRatio(): Promise<GetMaxZoomRatioResult> {
139-
throw this.createUnavailableException();
139+
throw this.createUnimplementedException();
140140
}
141141

142142
async openSettings(): Promise<void> {
143-
throw this.createUnavailableException();
143+
throw this.createUnimplementedException();
144144
}
145145

146146
async isGoogleBarcodeScannerModuleAvailable(): Promise<IsGoogleBarcodeScannerModuleAvailableResult> {
147-
throw this.createUnavailableException();
147+
throw this.createUnimplementedException();
148148
}
149149

150150
async installGoogleBarcodeScannerModule(): Promise<void> {
151-
throw this.createUnavailableException();
151+
throw this.createUnimplementedException();
152152
}
153153

154154
async checkPermissions(): Promise<PermissionStatus> {
@@ -180,10 +180,10 @@ export class BarcodeScannerWeb
180180
}
181181
}
182182

183-
private createUnavailableException(): CapacitorException {
183+
private createUnimplementedException(): CapacitorException {
184184
return new CapacitorException(
185-
'This plugin method is not available on this platform.',
186-
ExceptionCode.Unavailable,
185+
'This method is not implemented on web.',
186+
ExceptionCode.Unimplemented,
187187
);
188188
}
189189

packages/face-detection/BREAKING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ This is a comprehensive list of the breaking changes introduced in the major ver
1414

1515
This plugin now supports **Capacitor 8**. The minimum Android SDK version is **36**. Ensure your project meets these requirements before upgrading.
1616

17+
### Error codes
18+
19+
On **Web**, unimplemented methods now throw an error with code `Unimplemented` instead of `Unavailable`.
20+
1721
## Version 7.x.x
1822

1923
### Variables

packages/face-detection/src/web.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export class FaceDetectionWeb extends WebPlugin implements FaceDetectionPlugin {
1010
public async processImage(
1111
_options: ProcessImageOptions,
1212
): Promise<ProcessImageResult> {
13-
throw this.createUnavailableException();
13+
throw this.createUnimplementedException();
1414
}
1515

16-
private createUnavailableException(): CapacitorException {
16+
private createUnimplementedException(): CapacitorException {
1717
return new CapacitorException(
18-
'This Face Detection plugin method is not available on this platform.',
19-
ExceptionCode.Unavailable,
18+
'This method is not implemented on web.',
19+
ExceptionCode.Unimplemented,
2020
);
2121
}
2222
}

packages/face-mesh-detection/BREAKING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ This is a comprehensive list of the breaking changes introduced in the major ver
1313

1414
This plugin now supports **Capacitor 8**. The minimum Android SDK version is **36**. Ensure your project meets these requirements before upgrading.
1515

16+
### Error codes
17+
18+
On **Web**, unimplemented methods now throw an error with code `Unimplemented` instead of `Unavailable`.
19+
1620
## Version 6.x.x
1721

1822
### Variables

packages/face-mesh-detection/src/web.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ export class FaceMeshDetectionWeb
1313
public async processImage(
1414
_options: ProcessImageOptions,
1515
): Promise<ProcessImageResult> {
16-
throw this.createUnavailableException();
16+
throw this.createUnimplementedException();
1717
}
1818

19-
private createUnavailableException(): CapacitorException {
19+
private createUnimplementedException(): CapacitorException {
2020
return new CapacitorException(
21-
'This Face Mesh Detection plugin method is not available on this platform.',
22-
ExceptionCode.Unavailable,
21+
'This method is not implemented on web.',
22+
ExceptionCode.Unimplemented,
2323
);
2424
}
2525
}

packages/selfie-segmentation/BREAKING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ This is a comprehensive list of the breaking changes introduced in the major ver
1414

1515
This plugin now supports **Capacitor 8**. The minimum Android SDK version is **36**. Ensure your project meets these requirements before upgrading.
1616

17+
### Error codes
18+
19+
On **Web**, unimplemented methods now throw an error with code `Unimplemented` instead of `Unavailable`.
20+
1721
## Version 7.x.x
1822

1923
### Variables

packages/selfie-segmentation/src/web.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ export class SelfieSegmentationWeb
1313
public async processImage(
1414
_options: ProcessImageOptions,
1515
): Promise<ProcessImageResult> {
16-
throw this.createUnavailableException();
16+
throw this.createUnimplementedException();
1717
}
1818

19-
private createUnavailableException(): CapacitorException {
19+
private createUnimplementedException(): CapacitorException {
2020
return new CapacitorException(
21-
'This Selfie Segmentation plugin method is not available on this platform.',
22-
ExceptionCode.Unavailable,
21+
'This method is not implemented on web.',
22+
ExceptionCode.Unimplemented,
2323
);
2424
}
2525
}

0 commit comments

Comments
 (0)