fix(js): fix sentry errors

This commit is contained in:
Paul Chavard 2024-10-22 22:09:43 +02:00
parent f04e052dc9
commit b5c7e78bbf
No known key found for this signature in database
3 changed files with 24 additions and 20 deletions

View file

@ -1,13 +1,13 @@
import { httpRequest, ResponseError, getConfig } from '@utils';
import { matchInputElement, isButtonElement } from '@coldwired/utils';
import { isButtonElement, matchInputElement } from '@coldwired/utils';
import { getConfig, httpRequest, ResponseError } from '@utils';
import { ApplicationController } from './application_controller';
import { AutoUpload } from '../shared/activestorage/auto-upload';
import {
FileUploadError,
ERROR_CODE_READ,
FAILURE_CLIENT,
ERROR_CODE_READ
FileUploadError
} from '../shared/activestorage/file-upload-error';
import { ApplicationController } from './application_controller';
const {
autosave: { debounce_delay }
@ -182,7 +182,7 @@ export class AutosaveController extends ApplicationController {
.catch((e) => {
const error = e as FileUploadError;
this.globalDispatch('autosave:error');
this.globalDispatch('autosave:error', { error });
// Report unexpected client errors to Sentry.
// (But ignore usual client errors, or errors we can monitor better on the server side.)

View file

@ -36,7 +36,7 @@ export class DateInputHintController extends ApplicationController {
private translatePlaceholder() {
const locale = document.documentElement.lang as 'fr' | 'en';
const parts = PARTS[locale];
const parts = PARTS[locale] ?? PARTS.fr;
const example = new Date(2022, 9, 15).toLocaleDateString();
return [
Object.entries(parts).reduce(

View file

@ -1,11 +1,12 @@
import { httpRequest } from '@utils';
import { show, hide } from '@utils';
import { hide, httpRequest, show } from '@utils';
import { ApplicationController } from './application_controller';
type checkEmailResponse = {
success: boolean;
suggestions: string[];
};
type CheckEmailResponse =
| {
success: true;
suggestions: string[];
}
| { success: false };
export class EmailInputController extends ApplicationController {
static targets = ['ariaRegion', 'suggestion', 'input'];
@ -32,14 +33,17 @@ export class EmailInputController extends ApplicationController {
const url = new URL(this.urlValue, document.baseURI);
url.searchParams.append('email', this.inputTarget.value);
const data: checkEmailResponse | null = await httpRequest(
url.toString()
).json();
const data = await httpRequest(url.toString())
.json<CheckEmailResponse>()
.catch(() => null);
if (data && data.suggestions && data.suggestions.length > 0) {
this.suggestionTarget.innerHTML = data.suggestions[0];
show(this.ariaRegionTarget);
this.ariaRegionTarget.focus();
if (data?.success) {
const suggestion = data.suggestions.at(0);
if (suggestion) {
this.suggestionTarget.innerHTML = suggestion;
show(this.ariaRegionTarget);
this.ariaRegionTarget.focus();
}
}
}