mirror of
https://github.com/immich-app/immich.git
synced 2025-01-04 02:46:47 +01:00
fix(web): don't log unauthorized errors
This commit is contained in:
parent
09a1d56bf3
commit
7fc2987a77
2 changed files with 20 additions and 13 deletions
|
@ -4,10 +4,24 @@ import { env } from '$env/dynamic/public';
|
||||||
import { ImmichApi } from './api/api';
|
import { ImmichApi } from './api/api';
|
||||||
|
|
||||||
export const handle = (async ({ event, resolve }) => {
|
export const handle = (async ({ event, resolve }) => {
|
||||||
event.locals.api = new ImmichApi({
|
const basePath = env.PUBLIC_IMMICH_SERVER_URL || 'http://immich-server:3001';
|
||||||
basePath: env.PUBLIC_IMMICH_SERVER_URL || 'http://immich-server:3001',
|
const accessToken = event.cookies.get('immich_access_token');
|
||||||
accessToken: event.cookies.get('immich_access_token')
|
const api = new ImmichApi({ basePath, accessToken });
|
||||||
});
|
|
||||||
|
// API instance that should be used for all server-side requests.
|
||||||
|
event.locals.api = api;
|
||||||
|
|
||||||
|
if (accessToken) {
|
||||||
|
try {
|
||||||
|
const { data: user } = await api.userApi.getMyUserInfo();
|
||||||
|
event.locals.user = user;
|
||||||
|
} catch (err) {
|
||||||
|
// Ignore 401 unauthorized errors and log all others.
|
||||||
|
if (err instanceof AxiosError && err.response?.status !== 401) {
|
||||||
|
console.error('[ERROR] hooks.server.ts [handle]:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const res = await resolve(event);
|
const res = await resolve(event);
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
import type { LayoutServerLoad } from './$types';
|
import type { LayoutServerLoad } from './$types';
|
||||||
|
|
||||||
export const load = (async ({ locals: { api } }) => {
|
export const load = (async ({ locals: { user } }) => {
|
||||||
try {
|
return { user };
|
||||||
const { data: user } = await api.userApi.getMyUserInfo();
|
|
||||||
|
|
||||||
return { user };
|
|
||||||
} catch (e) {
|
|
||||||
console.error('[ERROR] layout.server.ts [LayoutServerLoad]: ');
|
|
||||||
return { user: undefined };
|
|
||||||
}
|
|
||||||
}) satisfies LayoutServerLoad;
|
}) satisfies LayoutServerLoad;
|
||||||
|
|
Loading…
Reference in a new issue