kopia lustrzana https://gitlab.com/rysiekpl/libresilient
minor improvements, including fetch plugin now returning 4xx errors directly as Response objects (ref. #36)
rodzic
f5facd288a
commit
5bae7cace6
|
@ -35,6 +35,11 @@
|
|||
// merge the defaults with settings from init
|
||||
let config = {...defaultConfig, ...init}
|
||||
|
||||
// reality check: if no wrapped plugin configured, or more than one, complain
|
||||
if (config.uses.length != 1) {
|
||||
throw new Error(`Expected exactly one plugin to wrap, but ${config.uses.length} configured.`)
|
||||
}
|
||||
|
||||
/**
|
||||
* getting content using regular HTTP(S) fetch()
|
||||
*/
|
||||
|
|
|
@ -32,13 +32,14 @@
|
|||
// run built-in regular fetch()
|
||||
return fetch(url, init)
|
||||
.then((response) => {
|
||||
// 4xx? 5xx? that's a paddlin'
|
||||
if (response.status >= 400) {
|
||||
// 5xx? that's a paddlin'
|
||||
// we do want to pass 3xx and 4xx on back to the client though!
|
||||
if (response.status >= 500) {
|
||||
// throw an Error to fall back to LibResilient:
|
||||
throw new Error('HTTP Error: ' + response.status + ' ' + response.statusText);
|
||||
}
|
||||
// all good, it seems
|
||||
LR.log(pluginName, `fetched successfully: ${response.url}`);
|
||||
LR.log(pluginName, `fetched:\n+-- url: ${response.url}\n+-- http status: ${response.status} (${response.statusText})`);
|
||||
|
||||
// we need to create a new Response object
|
||||
// with all the headers added explicitly,
|
||||
|
|
|
@ -820,6 +820,8 @@ let LibResilientClient = class {
|
|||
|
||||
constructor(clientId) {
|
||||
|
||||
self.log('service-worker', `new client: ${clientId}`)
|
||||
|
||||
// we often get the clientId long before
|
||||
// we are able to get a valid client out of it
|
||||
//
|
||||
|
|
Ładowanie…
Reference in New Issue