e729133134
* api: return 404 for alloc FS list/stat endpoints If the alloc filesystem doesn't have a file requested by the List Files or Stat File API, we currently return a HTTP 500 error with the expected "file not found" error message. Return a HTTP 404 error instead. * update FS Handler Previously the FS handler would interpret a 500 status as a 404 in the adapter layer by checking if the response body contained the text or is the response status was 500 and then throw an error code for 404. Co-authored-by: Jai Bhagat <jaybhagat841@gmail.com>
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
import Watchable from './watchable';
|
|
import addToPath from 'nomad-ui/utils/add-to-path';
|
|
|
|
export default class AllocationAdapter extends Watchable {
|
|
stop = adapterAction('/stop');
|
|
|
|
restart(allocation, taskName) {
|
|
const prefix = `${this.host || '/'}${this.urlPrefix()}`;
|
|
const url = `${prefix}/client/allocation/${allocation.id}/restart`;
|
|
return this.ajax(url, 'PUT', {
|
|
data: taskName && { TaskName: taskName },
|
|
});
|
|
}
|
|
|
|
ls(model, path) {
|
|
return this.token
|
|
.authorizedRequest(`/v1/client/fs/ls/${model.id}?path=${encodeURIComponent(path)}`)
|
|
.then(handleFSResponse);
|
|
}
|
|
|
|
stat(model, path) {
|
|
return this.token
|
|
.authorizedRequest(`/v1/client/fs/stat/${model.id}?path=${encodeURIComponent(path)}`)
|
|
.then(handleFSResponse);
|
|
}
|
|
}
|
|
|
|
async function handleFSResponse(response) {
|
|
if (response.ok) {
|
|
return response.json();
|
|
} else {
|
|
const body = await response.text();
|
|
|
|
throw {
|
|
code: response.status,
|
|
toString: () => body,
|
|
};
|
|
}
|
|
}
|
|
|
|
function adapterAction(path, verb = 'POST') {
|
|
return function(allocation) {
|
|
const url = addToPath(this.urlForFindRecord(allocation.id, 'allocation'), path);
|
|
return this.ajax(url, verb);
|
|
};
|
|
}
|