mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-14 18:44:05 +02:00
Add frontend autoformatting and set CI to require formatted code for all languages (#6052)
# Description of Changes Changes the strategy for autoformatting to reject PRs if they are not formatted correctly instead of allowing them to merge and then spawning a new PR to fix the formatting. The old strategy just caused more work for us because we'd have to manually approve the followup PR and get it merged, which required 2 reviewers so in practice it rarely got done and just meant everyone's PRs ended up containing reformatting for unrelated files, which makes code review unnecessarily difficult. If the PR's code is not formatted correctly after this PR, a comment will be added automatically to tell the author how to run the formatter script to fix their code so it can go in. This also enables autoformatting for the frontend code, using Prettier. I've enabled it for pretty much everything in the frontend folder, other than 3rd party files and files it doesn't make sense for. I also excluded Markdown because it sounds likely to be more annoying to have to autoformat the Markdown in the frontend folder but nowhere else. Open to changing this though if people disagree. > [!note] > > Advice to reviewers: The first commit contains all of the actual logic I've introduced (CI changes, Prettier config, etc.) > The second commit is just the reformatting of the entire frontend folder. > The first commit needs proper review, the second one just give it a spot-check that it's doing what you'd expect.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
// frontend/src/services/httpErrorHandler.ts
|
||||
import { alert } from '@app/components/toast';
|
||||
import { broadcastErroredFiles, extractErrorFileIds, normalizeAxiosErrorData } from '@app/services/errorUtils';
|
||||
import { showSpecialErrorToast } from '@app/services/specialErrorToasts';
|
||||
import { handleSaaSError } from '@app/services/saasErrorInterceptor';
|
||||
import { clampText, extractAxiosErrorMessage } from '@app/services/httpErrorUtils';
|
||||
import { alert } from "@app/components/toast";
|
||||
import { broadcastErroredFiles, extractErrorFileIds, normalizeAxiosErrorData } from "@app/services/errorUtils";
|
||||
import { showSpecialErrorToast } from "@app/services/specialErrorToasts";
|
||||
import { handleSaaSError } from "@app/services/saasErrorInterceptor";
|
||||
import { clampText, extractAxiosErrorMessage } from "@app/services/httpErrorUtils";
|
||||
|
||||
// Module-scoped state to reduce global variable usage
|
||||
const recentSpecialByEndpoint: Record<string, number> = {};
|
||||
@@ -26,30 +26,31 @@ export async function handleHttpError(error: any): Promise<boolean> {
|
||||
const pathname = window.location.pathname;
|
||||
|
||||
// Check if we're already on an auth page
|
||||
const isAuthPage = pathname.includes('/login') ||
|
||||
pathname.includes('/signup') ||
|
||||
pathname.includes('/auth/') ||
|
||||
pathname.includes('/invite/');
|
||||
const isAuthPage =
|
||||
pathname.includes("/login") ||
|
||||
pathname.includes("/signup") ||
|
||||
pathname.includes("/auth/") ||
|
||||
pathname.includes("/invite/");
|
||||
|
||||
// If not on auth page, redirect to login with expired session message
|
||||
if (!isAuthPage && !skipAuthRedirect) {
|
||||
console.debug('[httpErrorHandler] 401 detected, redirecting to login');
|
||||
console.debug("[httpErrorHandler] 401 detected, redirecting to login");
|
||||
// Store the current location so we can redirect back after login
|
||||
const currentLocation = window.location.pathname + window.location.search;
|
||||
// Redirect to login with state (only show expired when a JWT existed)
|
||||
let hadStoredJwt = false;
|
||||
try {
|
||||
hadStoredJwt = Boolean(localStorage.getItem('stirling_jwt'));
|
||||
hadStoredJwt = Boolean(localStorage.getItem("stirling_jwt"));
|
||||
} catch {
|
||||
// ignore storage access failures
|
||||
}
|
||||
const expiredPrefix = hadStoredJwt ? 'expired=true&' : '';
|
||||
const expiredPrefix = hadStoredJwt ? "expired=true&" : "";
|
||||
window.location.href = `/login?${expiredPrefix}from=${encodeURIComponent(currentLocation)}`;
|
||||
return true; // Suppress toast since we're redirecting
|
||||
}
|
||||
|
||||
// On auth pages, suppress the toast (user is already trying to authenticate)
|
||||
console.debug('[httpErrorHandler] Suppressing 401 on auth page:', pathname);
|
||||
console.debug("[httpErrorHandler] Suppressing 401 on auth page:", pathname);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -59,9 +60,13 @@ export async function handleHttpError(error: any): Promise<boolean> {
|
||||
const { title, body } = extractAxiosErrorMessage(error);
|
||||
|
||||
// Normalize response data ONCE, reuse for both ID extraction and special-toast matching
|
||||
const raw = (error?.response?.data) as any;
|
||||
const raw = error?.response?.data as any;
|
||||
let normalized: unknown = raw;
|
||||
try { normalized = await normalizeAxiosErrorData(raw); } catch (e) { console.debug('normalizeAxiosErrorData', e); }
|
||||
try {
|
||||
normalized = await normalizeAxiosErrorData(raw);
|
||||
} catch (e) {
|
||||
console.debug("normalizeAxiosErrorData", e);
|
||||
}
|
||||
|
||||
// 1) If server sends structured file IDs for failures, also mark them errored in UI
|
||||
try {
|
||||
@@ -70,7 +75,7 @@ export async function handleHttpError(error: any): Promise<boolean> {
|
||||
broadcastErroredFiles(ids);
|
||||
}
|
||||
} catch (e) {
|
||||
console.debug('extractErrorFileIds', e);
|
||||
console.debug("extractErrorFileIds", e);
|
||||
}
|
||||
|
||||
// 2) Generic-vs-special dedupe by endpoint
|
||||
@@ -95,18 +100,15 @@ export async function handleHttpError(error: any): Promise<boolean> {
|
||||
// 3) Show specialized friendly toasts if matched; otherwise show the generic one
|
||||
let rawString: string | undefined;
|
||||
try {
|
||||
rawString =
|
||||
typeof normalized === 'string'
|
||||
? normalized
|
||||
: JSON.stringify(normalized);
|
||||
rawString = typeof normalized === "string" ? normalized : JSON.stringify(normalized);
|
||||
} catch (e) {
|
||||
console.debug('extractErrorFileIds', e);
|
||||
console.debug("extractErrorFileIds", e);
|
||||
}
|
||||
|
||||
const handled = showSpecialErrorToast(rawString, { status });
|
||||
if (!handled) {
|
||||
const displayBody = clampText(body);
|
||||
alert({ alertType: 'error', title, body: displayBody, expandable: true, isPersistentPopup: false });
|
||||
alert({ alertType: "error", title, body: displayBody, expandable: true, isPersistentPopup: false });
|
||||
}
|
||||
|
||||
return false; // Error was handled with toast, continue normal rejection
|
||||
|
||||
Reference in New Issue
Block a user