github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/app/adapters/task-state.js (about) 1 import ApplicationAdapter from './application'; 2 import { inject as service } from '@ember/service'; 3 4 export default ApplicationAdapter.extend({ 5 token: service(), 6 7 ls(model, path) { 8 return this.token 9 .authorizedRequest(`/v1/client/fs/ls/${model.allocation.id}?path=${encodeURIComponent(path)}`) 10 .then(handleFSResponse); 11 }, 12 13 stat(model, path) { 14 return this.token 15 .authorizedRequest( 16 `/v1/client/fs/stat/${model.allocation.id}?path=${encodeURIComponent(path)}` 17 ) 18 .then(handleFSResponse); 19 }, 20 }); 21 22 async function handleFSResponse(response) { 23 if (response.ok) { 24 return response.json(); 25 } else { 26 const body = await response.text(); 27 28 // TODO update this if/when endpoint returns 404 as expected 29 const statusIs500 = response.status === 500; 30 const bodyIncludes404Text = body.includes('no such file or directory'); 31 32 const translatedCode = statusIs500 && bodyIncludes404Text ? 404 : response.status; 33 34 throw { 35 code: translatedCode, 36 toString: () => body, 37 }; 38 } 39 }