Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exception handling #2277

Merged
merged 1 commit into from Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/api/src/Domain/Http/HttpService.ts
Expand Up @@ -310,12 +310,22 @@ export class HttpService implements HttpServiceInterface {
},
}
}

if (isString(errorResponse.data)) {
errorResponse.data = {
error: {
message: errorResponse.data,
},
}
}

if (!errorResponse.data.error) {
errorResponse.data.error = {
message: 'Unknown error',
}
}
resolve(response as HttpErrorResponse)

resolve(errorResponse)
}
}

Expand Down
18 changes: 15 additions & 3 deletions packages/web/src/javascripts/Controllers/Moments/PhotoRecorder.ts
Expand Up @@ -3,10 +3,10 @@ export class PhotoRecorder {
public devices!: MediaDeviceInfo[]
public selectedDevice!: MediaDeviceInfo

private canvas!: HTMLCanvasElement
private canvas?: HTMLCanvasElement
private width!: number
private height!: number
private stream!: MediaStream
private stream?: MediaStream

// eslint-disable-next-line @typescript-eslint/no-empty-function
constructor() {}
Expand All @@ -33,6 +33,10 @@ export class PhotoRecorder {

public async initialize() {
this.devices = (await navigator.mediaDevices.enumerateDevices()).filter((device) => device.kind === 'videoinput')
if (this.devices.length === 0) {
return
}

this.selectedDevice = this.devices[0]

this.stream = await navigator.mediaDevices.getUserMedia({
Expand Down Expand Up @@ -66,6 +70,10 @@ export class PhotoRecorder {
}

public async takePhoto(fileName: string): Promise<File | undefined> {
if (!this.canvas) {
return undefined
}

const context = this.canvas.getContext('2d')
context?.drawImage(this.video, 0, 0, this.width, this.height)
const dataUrl = this.canvas.toDataURL('image/png')
Expand All @@ -83,6 +91,10 @@ export class PhotoRecorder {
}

public finish() {
if (!this.canvas || !this.video) {
return
}

this.video.pause()

this.video.parentElement?.removeChild(this.video)
Expand All @@ -91,7 +103,7 @@ export class PhotoRecorder {
this.video.remove()
this.canvas.remove()

this.stream.getTracks().forEach((track) => {
this.stream?.getTracks().forEach((track) => {
track.stop()
})
}
Expand Down