mirror of
https://github.com/janishutz/oidc-login-sdk.git
synced 2026-10-08 17:36:20 +02:00
feat: better error handling
This commit is contained in:
1 parent
bc898d6f0f
commit
d1df43c57a
3 files changed
+14
-2
No files matched your search
@@ -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
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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> => {
|
||||||
|
try {
|
||||||
return await wrapper( url, {
|
return await wrapper( url, {
|
||||||
'credentials': 'include'
|
'credentials': 'include'
|
||||||
}, authErrorResolution );
|
}, authErrorResolution );
|
||||||
|
} catch ( e ) {
|
||||||
|
throw await e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +35,7 @@ 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> => {
|
||||||
|
try {
|
||||||
return await wrapper( url, {
|
return await wrapper( url, {
|
||||||
'credentials': 'include',
|
'credentials': 'include',
|
||||||
'body': payload,
|
'body': payload,
|
||||||
@@ -39,6 +44,9 @@ export const post = async ( url: string, payload: string, mime: string = 'applic
|
|||||||
'Content-Type': mime ?? 'application/json'
|
'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> => {
|
||||||
|
try {
|
||||||
return await wrapper( url, {
|
return await wrapper( url, {
|
||||||
'credentials': 'include',
|
'credentials': 'include',
|
||||||
'method': 'delete'
|
'method': 'delete'
|
||||||
}, authErrorResolution );
|
}, authErrorResolution );
|
||||||
|
} catch ( e ) {
|
||||||
|
throw await e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user