Skip to content

Commit

Permalink
WIP Fetcher linkeddata#355
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Nov 4, 2019
1 parent 77e2af5 commit ee8b9ae
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions src/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ interface Options {
original?: any
// Is this a serialized resource?
data?: any
credentials?: any
retriedWithNoCredentials?: boolean
}

class Handler {
Expand Down Expand Up @@ -541,7 +543,7 @@ interface FetchCallbacks {
}

interface Nonexistent {
[uri: string]: string
[uri: string]: boolean
}

interface Lookedup {
Expand Down Expand Up @@ -1096,7 +1098,7 @@ export default class Fetcher {
options: Options,
errorMessage: string,
statusCode: number,
response: Response
response?: Response
): Promise<{}> {
this.addStatus(options.req, errorMessage)

Expand Down Expand Up @@ -1642,14 +1644,12 @@ export default class Fetcher {
/**
* Called when there's a network error in fetch(), or a response
* with status of 0.
*
* @param response {Response|Error}
* @param docuri {string}
* @param options {Object}
*
* @returns {Promise}
*/
handleError (response, docuri, options) {
handleError (
response: Response | Error,
docuri: string,
options: Options
): Promise<any> {
if (this.isCrossSite(docuri)) {
// Make sure we haven't retried already
if (options.credentials && options.credentials === 'include' && !options.retriedWithNoCredentials) {
Expand Down Expand Up @@ -1706,12 +1706,12 @@ export default class Fetcher {

/**
* Handle fetch() response
*
* @param response {Response} fetch() response object
* @param docuri {string}
* @param options {Object}
*/
handleResponse (response, docuri, options) {
handleResponse (
response: Response,
docuri: string,
options: Options
): Promise<string> {
const kb = this.store
const headers = response.headers

Expand Down Expand Up @@ -1820,12 +1820,7 @@ export default class Fetcher {
})
}

/**
* @param contentType {string}
*
* @returns {Handler|null}
*/
handlerForContentType (contentType, response) {
handlerForContentType (contentType: string, response): Handler | null {
if (!contentType) {
return null
}
Expand All @@ -1837,12 +1832,7 @@ export default class Fetcher {
return Handler ? new Handler(response) : null
}

/**
* @param uri {string}
*
* @returns {string}
*/
guessContentType (uri) {
guessContentType (uri: string): string | undefined {
return CONTENT_TYPE_BY_EXT[uri.split('.').pop()]
}

Expand Down

0 comments on commit ee8b9ae

Please sign in to comment.