Permalink
Browse files

fix(rest): Do not set responseType on request

  • Loading branch information...
mvrueden committed Aug 28, 2017
1 parent aa9257d commit 0c2b6f401721e4dfdb9d44fe46bbd7bdd5d38b53
Showing with 9 additions and 23 deletions.
  1. +9 −23 src/rest/GrafanaHTTP.ts
View
@@ -140,40 +140,26 @@ export class GrafanaHTTP extends AbstractHTTP {
*/
private getConfig(options?: OnmsHTTPOptions): any {
const allOptions = this.getOptions(options);
const ret = {
transformResponse: [], // we do this so we can post-process only on success
} as any;
const ret = clonedeep(allOptions);
ret.transformResponse = []; // we do this so we can post-process only on success
if (allOptions.headers) {
if (!allOptions.headers) {
ret.headers = clonedeep(allOptions.headers);
} else {
ret.headers = {};
}
// Enforce Accept-Header
if (!ret.headers.accept) {
ret.headers.accept = 'application/json';
}
if (!ret.headers['content-type']) {
// Enforce Content-Type-Header when data is being sent
if (ret.data && !ret.headers['content-type']) {
ret.headers['content-type'] = 'application/json;charset=utf-8';
}
const type = ret.headers.accept;
if (type === 'application/json') {
ret.responseType = 'json';
} else if (type === 'text/plain') {
ret.responseType = 'text';
} else if (type === 'application/xml') {
ret.responseType = 'text';
} else {
throw new OnmsError('Unhandled "Accept" header: ' + type);
}
if (allOptions.parameters && Object.keys(allOptions.parameters).length > 0) {
ret.params = clonedeep(allOptions.parameters);
}
if (allOptions.data) {
ret.data = clonedeep(allOptions.data);
if (ret.parameters && Object.keys(ret.parameters).length > 0) {
ret.params = ret.parameters;
delete ret.parameters;
}
return ret;
}

0 comments on commit 0c2b6f4

Please sign in to comment.