Merge pull request #213 from Jigsaw-Code/trevj-api-logging

add a little more detail to api request failures
This commit is contained in:
trevj 2018-07-30 16:21:29 -04:00 • committed by GitHub
commit bdcd63c8f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,7 +19,9 @@ import {SentryErrorReporter} from './error_reporter';
interface MetricsEnabled {
metricsEnabled: boolean;
}
export interface ServerName { name: string; }
export interface ServerName {
name: string;
}
export interface ServerConfig {
name: string;
metricsEnabled: boolean;
@ -171,21 +173,22 @@ export class ShadowboxServer implements server.Server {
apiAddress += '/';
}
const url = apiAddress + path;
console.log(`Fetching url ${url}...`);
return fetch(url, options)
.then(
(response) => {
console.log('Fetch result:', url, response.ok);
if (!response.ok) {
const msg = 'Failed to fetch API request results';
const msg = `API request to ${path} failed with status ${response.status}, type ${
response.type}`;
console.error(msg);
SentryErrorReporter.logError(msg);
throw new Error(msg);
}
console.debug(`API request to ${path} succeeded`);
return response.text();
},
(error: Error) => {
const msg = 'Failed to fetch url';
console.error(msg, url, error);
(error) => {
const msg = `API request to ${path} failed due to network error`;
console.error(msg, error);
SentryErrorReporter.logError(msg);
throw error;
})