Skip to content

Commit

Permalink
fix(getIdFromHeaders): Return undefined if not available (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
simenandre authored Mar 16, 2021
1 parent ceae9db commit e12017c
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/libs/id-from-header.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
/**
* Get ID from `location` header
*
*
* This function is used to get the ID resources
* created in Folio (where you are redirected
* afterwards).
*
*
* @example
* ```typescript
* import { getIDFromHeaders } from 'fiken';
*
*
* ...
*
*
* const res = await fiken.createBankAccountRaw({
* ...
* });
*
*
* const id = getIDFromHeaders(res.raw);
* ```
*/
export function getIDFromHeaders(resp: Response): string {
const loc = resp.headers.get('location');
if (!loc) {
throw new Error('location header was not found');
}
export function getIDFromHeaders(resp: Response): string | undefined {
if (!resp.headers) return;
const loc = resp.headers.get('location');
if (!loc) return;

const url = loc.split('/');
return url.pop();
}
const url = loc.split('/');
return url.pop();
}

0 comments on commit e12017c

Please sign in to comment.