mirror of
https://github.com/status-im/consul.git
synced 2025-01-24 20:51:10 +00:00
6589cbbd0d
* ui: Add the most basic workspace root in /ui * We already have a LICENSE file in the repository root * Change directory path in build scripts ui-v2 -> ui * Make yarn install flags configurable from elsewhere * Minimal workspace root makefile * Call the new docker specific target * Update yarn in the docker build image * Reconfigure the netlify target and move to the higher makefile * Move ui-v2 -> ui/packages/consul-ui * Change repo root to refleect new folder structure * Temporarily don't hoist consul-api-double * Fixup CI configuration * Fixup lint errors * Fixup Netlify target
62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
import Service from '@ember/service';
|
|
|
|
import createHeaders from 'consul-ui/utils/http/create-headers';
|
|
import createXHR from 'consul-ui/utils/http/xhr';
|
|
import Request from 'consul-ui/utils/http/request';
|
|
import HTTPError from 'consul-ui/utils/http/error';
|
|
|
|
const xhr = createXHR(createHeaders());
|
|
|
|
export default Service.extend({
|
|
xhr: function(options) {
|
|
return xhr(options);
|
|
},
|
|
request: function(params) {
|
|
const request = new Request(params.method, params.url, {
|
|
['x-request-id']: params.clientHeaders['x-request-id'],
|
|
body: params.data || {},
|
|
});
|
|
const options = {
|
|
...params,
|
|
beforeSend: function(xhr) {
|
|
request.open(xhr);
|
|
},
|
|
converters: {
|
|
'text json': function(response) {
|
|
try {
|
|
return JSON.parse(response);
|
|
} catch (e) {
|
|
return response;
|
|
}
|
|
},
|
|
},
|
|
success: function(headers, response, status, statusText) {
|
|
// Response-ish
|
|
request.respond({
|
|
headers: headers,
|
|
response: response,
|
|
status: status,
|
|
statusText: statusText,
|
|
});
|
|
},
|
|
error: function(headers, response, status, statusText, err) {
|
|
let error;
|
|
if (err instanceof Error) {
|
|
error = err;
|
|
} else {
|
|
error = new HTTPError(status, response);
|
|
}
|
|
request.error(error);
|
|
},
|
|
complete: function(status) {
|
|
request.close();
|
|
},
|
|
};
|
|
request.fetch = () => {
|
|
this.xhr(options);
|
|
return request;
|
|
};
|
|
return request;
|
|
},
|
|
});
|