@@ -21,18 +21,21 @@ type ApiCtx struct {
21
21
}
22
22
23
23
// CreateApiCtx initializes an instance of ApiCtx
24
- func CreateApiCtx (http * transport.HttpClientCtx ) * ApiCtx {
25
- return & ApiCtx {http , DocumentsFileTree (http )}
24
+ func CreateApiCtx (http * transport.HttpClientCtx ) (* ApiCtx , error ) {
25
+ fileTree , err := DocumentsFileTree (http )
26
+ if err != nil {
27
+ return nil , fmt .Errorf ("failed to fetch document tree %w" , err )
28
+ }
29
+ return & ApiCtx {http , fileTree }, nil
26
30
}
27
31
28
32
// DocumentsFileTree reads your remote documents and builds a file tree
29
33
// structure to represent them
30
- func DocumentsFileTree (http * transport.HttpClientCtx ) * filetree.FileTreeCtx {
34
+ func DocumentsFileTree (http * transport.HttpClientCtx ) ( * filetree.FileTreeCtx , error ) {
31
35
documents := make ([]model.Document , 0 )
32
36
33
37
if err := http .Get (transport .UserBearer , listDocs , nil , & documents ); err != nil {
34
- log .Error .Println ("failed to fetch documents" , err .Error ())
35
- return nil
38
+ return nil , err
36
39
}
37
40
38
41
fileTree := filetree .CreateFileTreeCtx ()
@@ -45,7 +48,7 @@ func DocumentsFileTree(http *transport.HttpClientCtx) *filetree.FileTreeCtx {
45
48
log .Trace .Println (d .Name (), d .IsFile ())
46
49
}
47
50
48
- return & fileTree
51
+ return & fileTree , nil
49
52
}
50
53
51
54
// FetchDocument downloads a document given its ID and saves it locally into dstPath
0 commit comments