feat: harden community production foundation through story 1.5
This commit is contained in:
+15
-3
@@ -8,6 +8,18 @@
|
||||
}, extra || {});
|
||||
}
|
||||
|
||||
function attachCorrelation(error, response) {
|
||||
var requestId = response.headers.get('x-request-id');
|
||||
var traceId = response.headers.get('x-trace-id');
|
||||
if (requestId && requestId.length <= 128 && /^[!-~]+$/.test(requestId) && requestId.indexOf(',') === -1 && requestId.indexOf(';') === -1) {
|
||||
error.requestId = requestId;
|
||||
}
|
||||
if (traceId && /^[0-9a-f]{32}$/.test(traceId) && traceId !== '00000000000000000000000000000000') {
|
||||
error.traceId = traceId;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
async function request(path, options) {
|
||||
var response = await fetch(path, Object.assign({
|
||||
credentials: 'same-origin',
|
||||
@@ -42,11 +54,11 @@
|
||||
var error = new Error(message);
|
||||
error.status = response.status;
|
||||
error.payload = payload;
|
||||
throw error;
|
||||
throw attachCorrelation(error, response);
|
||||
}
|
||||
|
||||
if (text && payload === null) {
|
||||
throw new Error('Backend returned a non-JSON response');
|
||||
throw attachCorrelation(new Error('Backend returned a non-JSON response'), response);
|
||||
}
|
||||
|
||||
return payload;
|
||||
@@ -81,7 +93,7 @@
|
||||
var error = new Error(message);
|
||||
error.status = response.status;
|
||||
error.payload = payload;
|
||||
throw error;
|
||||
throw attachCorrelation(error, response);
|
||||
}
|
||||
|
||||
return text;
|
||||
|
||||
Reference in New Issue
Block a user