Merge pull request #10978 from tchak/fix-some-sentry-js-errors

fix(js): fix sentry errors
This commit is contained in:
Paul Chavard 2024-10-23 09:23:22 +00:00 committed by GitHub
commit 05913b4409
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 20 deletions

View file

@ -1,13 +1,13 @@
import { httpRequest, ResponseError, getConfig } from '@utils'; import { isButtonElement, matchInputElement } from '@coldwired/utils';
import { matchInputElement, isButtonElement } from '@coldwired/utils'; import { getConfig, httpRequest, ResponseError } from '@utils';
import { ApplicationController } from './application_controller';
import { AutoUpload } from '../shared/activestorage/auto-upload'; import { AutoUpload } from '../shared/activestorage/auto-upload';
import { import {
FileUploadError, ERROR_CODE_READ,
FAILURE_CLIENT, FAILURE_CLIENT,
ERROR_CODE_READ FileUploadError
} from '../shared/activestorage/file-upload-error'; } from '../shared/activestorage/file-upload-error';
import { ApplicationController } from './application_controller';
const { const {
autosave: { debounce_delay } autosave: { debounce_delay }
@ -182,7 +182,7 @@ export class AutosaveController extends ApplicationController {
.catch((e) => { .catch((e) => {
const error = e as FileUploadError; const error = e as FileUploadError;
this.globalDispatch('autosave:error'); this.globalDispatch('autosave:error', { error });
// Report unexpected client errors to Sentry. // Report unexpected client errors to Sentry.
// (But ignore usual client errors, or errors we can monitor better on the server side.) // (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() { private translatePlaceholder() {
const locale = document.documentElement.lang as 'fr' | 'en'; 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(); const example = new Date(2022, 9, 15).toLocaleDateString();
return [ return [
Object.entries(parts).reduce( Object.entries(parts).reduce(

View file

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