feat: better error handling

This commit is contained in:
janishutz committed 2026-09-23 15:24:27 +02:00
1 parent bc898d6f0f
commit d1df43c57a
3 files changed
+29 -17

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@janishutz/oidc-login-sdk-browser", "name": "@janishutz/oidc-login-sdk-browser",
"version": "1.3.5", "version": "1.4.0",
"description": "SDK to communicate with and log into a backend running express-openid-connect", "description": "SDK to communicate with and log into a backend running express-openid-connect",
"homepage": "https://github.com/janishutz/oidc-login-sdk#readme", "homepage": "https://github.com/janishutz/oidc-login-sdk#readme",
"bugs": { "bugs": {
+1 -1
View File
@@ -30,7 +30,7 @@ export const check = async (): Promise<boolean> => {
if ( e instanceof AuthError ) { if ( e instanceof AuthError ) {
status = false; status = false;
} else { } else {
throw e; throw await e;
} }
} }
+27 -15
View File
@@ -17,9 +17,13 @@ export class UnownedError extends Error {}
* @returns The reponse * @returns The reponse
*/ */
export const get = async ( url: string, authErrorResolution?: AuthErrorResolution ): Promise<Response> => { export const get = async ( url: string, authErrorResolution?: AuthErrorResolution ): Promise<Response> => {
return await wrapper( url, { try {
'credentials': 'include' return await wrapper( url, {
}, authErrorResolution ); 'credentials': 'include'
}, authErrorResolution );
} catch ( e ) {
throw await e;
}
}; };
/** /**
@@ -31,14 +35,18 @@ export const get = async ( url: string, authErrorResolution?: AuthErrorResolutio
* @returns The response * @returns The response
*/ */
export const post = async ( url: string, payload: string, mime: string = 'application/json', authErrorResolution?: AuthErrorResolution ): Promise<Response> => { export const post = async ( url: string, payload: string, mime: string = 'application/json', authErrorResolution?: AuthErrorResolution ): Promise<Response> => {
return await wrapper( url, { try {
'credentials': 'include', return await wrapper( url, {
'body': payload, 'credentials': 'include',
'method': 'post', 'body': payload,
'headers': { 'method': 'post',
'Content-Type': mime ?? 'application/json' 'headers': {
} 'Content-Type': mime ?? 'application/json'
}, authErrorResolution ); }
}, authErrorResolution );
} catch ( e ) {
throw await e;
}
}; };
/** /**
@@ -48,10 +56,14 @@ export const post = async ( url: string, payload: string, mime: string = 'applic
* @returns The response * @returns The response
*/ */
export const deleteRequest = async ( url: string, authErrorResolution?: AuthErrorResolution ): Promise<Response> => { export const deleteRequest = async ( url: string, authErrorResolution?: AuthErrorResolution ): Promise<Response> => {
return await wrapper( url, { try {
'credentials': 'include', return await wrapper( url, {
'method': 'delete' 'credentials': 'include',
}, authErrorResolution ); 'method': 'delete'
}, authErrorResolution );
} catch ( e ) {
throw await e;
}
}; };
/** /**