File tree Expand file tree Collapse file tree 4 files changed +11
-31
lines changed
Expand file tree Collapse file tree 4 files changed +11
-31
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,8 @@ export abstract class Client extends EventEmitter<{'status': RoundStatus}>{
178178 url . pathname += `tasks/${ this . task . id } /model.json`
179179
180180 const response = await fetch ( url ) ;
181+ if ( ! response . ok ) throw new Error ( `fetch: HTTP status ${ response . status } ` ) ;
182+
181183 const encoded = new Uint8Array ( await response . arrayBuffer ( ) )
182184 return await serialization . model . decode ( encoded )
183185 }
Original file line number Diff line number Diff line change @@ -20,20 +20,22 @@ export async function pushTask<D extends DataType>(
2020 task : Task < D > ,
2121 model : Model < D > ,
2222) : Promise < void > {
23- await fetch ( urlToTasks ( base ) , {
23+ const response = await fetch ( urlToTasks ( base ) , {
2424 method : "POST" ,
2525 body : JSON . stringify ( {
2626 task,
2727 model : await serialization . model . encode ( model ) ,
2828 weights : await serialization . weights . encode ( model . weights ) ,
2929 } ) ,
3030 } ) ;
31+ if ( ! response . ok ) throw new Error ( `fetch: HTTP status ${ response . status } ` ) ;
3132}
3233
3334export async function fetchTasks (
3435 base : URL ,
3536) : Promise < Map < TaskID , Task < DataType > > > {
3637 const response = await fetch ( urlToTasks ( base ) ) ;
38+ if ( ! response . ok ) throw new Error ( `fetch: HTTP status ${ response . status } ` ) ;
3739 const tasks : unknown = await response . json ( ) ;
3840
3941 if ( ! Array . isArray ( tasks ) ) {
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ it("shows stored models", async () => {
6060it ( "allows to download server's models" , async ( ) => {
6161 vi . stubGlobal ( "fetch" , async ( url : string | URL ) => {
6262 if ( url . toString ( ) === "http://localhost:8080/tasks" )
63- return { json : ( ) => Promise . resolve ( [ TASK ] ) } ;
63+ return new Response ( JSON . stringify ( [ TASK ] ) ) ;
6464 throw new Error ( `unhandled get: ${ url } ` ) ;
6565 } ) ;
6666 afterEach ( ( ) => {
Original file line number Diff line number Diff line change @@ -10,39 +10,15 @@ import { loadCSV } from "@epfml/discojs-web";
1010import Trainer from "../Trainer.vue" ;
1111import TrainingInformation from "../TrainingInformation.vue" ;
1212
13- vi . mock ( "axios" , async ( ) => {
14- async function get ( url : string ) {
15- if ( url === "http://localhost:8080/tasks/titanic/model.json" ) {
16- return {
17- data : await serialization . model . encode (
18- await defaultTasks . titanic . getModel ( ) ,
19- ) ,
20- } ;
21- }
22- throw new Error ( "unhandled get" ) ;
23- }
24-
25- const axios = await vi . importActual < typeof import ( "axios" ) > ( "axios" ) ;
26- return {
27- ...axios ,
28- default : {
29- ...axios . default ,
30- get,
31- } ,
32- } ;
33- } ) ;
34-
3513async function setupForTask ( ) {
3614 const provider = defaultTasks . titanic ;
3715
3816 vi . stubGlobal ( "fetch" , async ( url : string | URL ) => {
39- if ( url . toString ( ) === "http://localhost:8080/tasks/titanic/model.json" )
40- return {
41- arrayBuffer : async ( ) => {
42- const model = await provider . getModel ( ) ;
43- return await serialization . model . encode ( model ) ;
44- } ,
45- } ;
17+ if ( url . toString ( ) === "http://localhost:8080/tasks/titanic/model.json" ) {
18+ const model = await provider . getModel ( ) ;
19+ const encoded = await serialization . model . encode ( model ) ;
20+ return new Response ( encoded ) ;
21+ }
4622 throw new Error ( `unhandled get: ${ url } ` ) ;
4723 } ) ;
4824 afterEach ( ( ) => {
You can’t perform that action at this time.
0 commit comments