Skip to content

Commit 9ea27f3

Browse files
committed
pnpm run format
1 parent 9b1cee0 commit 9ea27f3

5 files changed

Lines changed: 52 additions & 28 deletions

File tree

src/lib/errorhandling/ProblemDetails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isNumber, isObject, isString } from "$lib/typeguards";
1+
import { isNumber, isObject, isString } from '$lib/typeguards';
22

33
export interface ProblemDetails {
44
type: string;

src/lib/errorhandling/ValidationProblemDetails.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { isObject } from "$lib/typeguards";
2-
import type { ProblemDetails } from "./ProblemDetails";
1+
import { isObject } from '$lib/typeguards';
2+
import type { ProblemDetails } from './ProblemDetails';
33

44
export interface ValidationProblemDetails extends ProblemDetails {
55
errors: Record<string, string[]>;
66
}
77

8-
export function isValidationError(problemdetails: ProblemDetails): problemdetails is ValidationProblemDetails {
8+
export function isValidationError(
9+
problemdetails: ProblemDetails
10+
): problemdetails is ValidationProblemDetails {
911
return (
1012
problemdetails.type === 'Validation.Error' &&
1113
Object.hasOwn(problemdetails, 'errors') &&

src/lib/errorhandling/apiErrorHandling.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
import { isProblemDetails, type ProblemDetails } from '$lib/errorhandling/ProblemDetails';
2-
import { isError, isFetchError, isRequiredError, isResponseError } from '$lib/typeguards/errorGuards';
1+
import { type ProblemDetails, isProblemDetails } from '$lib/errorhandling/ProblemDetails';
2+
import {
3+
isError,
4+
isFetchError,
5+
isRequiredError,
6+
isResponseError,
7+
} from '$lib/typeguards/errorGuards';
38
import { toast } from 'svelte-sonner';
49
import { isValidationError as isValidationProblem } from './ValidationProblemDetails';
510

611
export type HandleProblemCallback = (problem: ProblemDetails) => boolean;
712

8-
async function handleResponseError(response: Response, handleProblemCallback: HandleProblemCallback | null) {
13+
async function handleResponseError(
14+
response: Response,
15+
handleProblemCallback: HandleProblemCallback | null
16+
) {
917
const contentTypeHeader = response.headers.get('Content-Type');
1018
if (!contentTypeHeader) {
1119
console.error('No content type header found in response');
@@ -21,16 +29,11 @@ async function handleResponseError(response: Response, handleProblemCallback: Ha
2129

2230
const problem = await response.json();
2331
if (!isProblemDetails(problem)) {
24-
console.error(
25-
'Content json is not a valid problemdetails object', problem
26-
);
32+
console.error('Content json is not a valid problemdetails object', problem);
2733
return null;
2834
}
2935

30-
console.groupCollapsed(
31-
`%cAPI Error: ${problem.title}`,
32-
'color: red; font-weight: bold;'
33-
);
36+
console.groupCollapsed(`%cAPI Error: ${problem.title}`, 'color: red; font-weight: bold;');
3437
console.log('%cType: ', 'font-weight: bold;', problem.type);
3538
console.log('%cStatus: ', 'font-weight: bold;', problem.status);
3639
console.log('%cRequest ID:', 'font-weight: bold;', problem.requestId);
@@ -42,7 +45,7 @@ async function handleResponseError(response: Response, handleProblemCallback: Ha
4245
console.groupCollapsed('%cField errors', 'font-style: italic;');
4346
for (const [field, messages] of Object.entries(problem.errors)) {
4447
console.group(`${field}`);
45-
messages.forEach(msg => console.log(`• ${msg}`));
48+
messages.forEach((msg) => console.log(`• ${msg}`));
4649
console.groupEnd();
4750
}
4851
console.groupEnd(); // end Field errors
@@ -86,7 +89,7 @@ export async function handleApiError(
8689
);
8790
console.log('%cParameter:', 'font-weight: bold;', error.field);
8891
console.log('%cMessage: ', 'font-style: italic;', error.message);
89-
console.trace(); // show stack trace so you know exactly where it bubbled up
92+
console.trace(); // show stack trace so you know exactly where it bubbled up
9093
console.groupEnd();
9194
} else {
9295
console.error(`Got ${error.name}`, error);

src/lib/stores/UserStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async function refreshSelf(): Promise<boolean> {
6464
} catch (error) {
6565
reset();
6666

67-
handleApiError(error, problem => problem.type !== 'Authentication.CookieMissingOrInvalid');
67+
handleApiError(error, (problem) => problem.type !== 'Authentication.CookieMissingOrInvalid');
6868

6969
return false;
7070
}

src/lib/typeguards/errorGuards.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
1-
import { FetchError as FetchErrorV1, RequiredError as RequiredErrorV1, ResponseError as ResponseErrorV1 } from "$lib/api/internal/v1";
2-
import { FetchError as FetchErrorV2, RequiredError as RequiredErrorV2, ResponseError as ResponseErrorV2 } from "$lib/api/internal/v2";
1+
import {
2+
FetchError as FetchErrorV1,
3+
RequiredError as RequiredErrorV1,
4+
ResponseError as ResponseErrorV1,
5+
} from '$lib/api/internal/v1';
6+
import {
7+
FetchError as FetchErrorV2,
8+
RequiredError as RequiredErrorV2,
9+
ResponseError as ResponseErrorV2,
10+
} from '$lib/api/internal/v2';
311

412
// TODO: Use Error.isError() when compatibility reaches Baseline (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/isError)
513
export function isError(error: unknown): error is Error {
6-
return error instanceof Error || (
7-
error !== null &&
8-
typeof error === 'object' &&
9-
Object.hasOwn(error, 'name') &&
10-
Object.hasOwn(error, 'cause') &&
11-
Object.hasOwn(error, 'message')
14+
return (
15+
error instanceof Error ||
16+
(error !== null &&
17+
typeof error === 'object' &&
18+
Object.hasOwn(error, 'name') &&
19+
Object.hasOwn(error, 'cause') &&
20+
Object.hasOwn(error, 'message'))
1221
);
1322
}
1423

1524
export function isResponseError(error: Error): error is ResponseErrorV1 | ResponseErrorV2 {
16-
return error instanceof ResponseErrorV1 || error instanceof ResponseErrorV2 || (error.name === 'ResponseError' && Object.hasOwn(error, 'response'));
25+
return (
26+
error instanceof ResponseErrorV1 ||
27+
error instanceof ResponseErrorV2 ||
28+
(error.name === 'ResponseError' && Object.hasOwn(error, 'response'))
29+
);
1730
}
1831
export function isFetchError(error: Error): error is FetchErrorV1 | FetchErrorV2 {
19-
return error instanceof FetchErrorV1 || error instanceof FetchErrorV2 || error.name === 'FetchError';
32+
return (
33+
error instanceof FetchErrorV1 || error instanceof FetchErrorV2 || error.name === 'FetchError'
34+
);
2035
}
2136
export function isRequiredError(error: Error): error is RequiredErrorV1 | RequiredErrorV2 {
22-
return error instanceof RequiredErrorV1 || error instanceof RequiredErrorV2 || error.name === 'RequiredError';
37+
return (
38+
error instanceof RequiredErrorV1 ||
39+
error instanceof RequiredErrorV2 ||
40+
error.name === 'RequiredError'
41+
);
2342
}

0 commit comments

Comments
 (0)