@@ -2,7 +2,6 @@ package iot
2
2
3
3
import (
4
4
"context"
5
- "encoding/json"
6
5
"fmt"
7
6
8
7
"github.com/antihax/optional"
@@ -50,7 +49,7 @@ func (cl *client) AddDevice(fqbn, name, serial, dType string) (string, error) {
50
49
}
51
50
dev , _ , err := cl .api .DevicesV2Api .DevicesV2Create (cl .ctx , payload )
52
51
if err != nil {
53
- err = fmt .Errorf ("creating device, %w" , err )
52
+ err = fmt .Errorf ("creating device, %w" , errorDetail ( err ) )
54
53
return "" , err
55
54
}
56
55
return dev .Id , nil
@@ -61,7 +60,7 @@ func (cl *client) AddDevice(fqbn, name, serial, dType string) (string, error) {
61
60
func (cl * client ) DeleteDevice (id string ) error {
62
61
_ , err := cl .api .DevicesV2Api .DevicesV2Delete (cl .ctx , id )
63
62
if err != nil {
64
- err = fmt .Errorf ("deleting device: %w" , err )
63
+ err = fmt .Errorf ("deleting device: %w" , errorDetail ( err ) )
65
64
return err
66
65
}
67
66
return nil
@@ -72,7 +71,7 @@ func (cl *client) DeleteDevice(id string) error {
72
71
func (cl * client ) ListDevices () ([]iotclient.ArduinoDevicev2 , error ) {
73
72
devices , _ , err := cl .api .DevicesV2Api .DevicesV2List (cl .ctx , nil )
74
73
if err != nil {
75
- err = fmt .Errorf ("listing devices: %w" , err )
74
+ err = fmt .Errorf ("listing devices: %w" , errorDetail ( err ) )
76
75
return nil , err
77
76
}
78
77
return devices , nil
@@ -89,7 +88,7 @@ func (cl *client) AddCertificate(id, csr string) (*iotclient.ArduinoCompressedv2
89
88
90
89
newCert , _ , err := cl .api .DevicesV2CertsApi .DevicesV2CertsCreate (cl .ctx , id , cert )
91
90
if err != nil {
92
- err = fmt .Errorf ("creating certificate, %w" , err )
91
+ err = fmt .Errorf ("creating certificate, %w" , errorDetail ( err ) )
93
92
return nil , err
94
93
}
95
94
@@ -99,12 +98,9 @@ func (cl *client) AddCertificate(id, csr string) (*iotclient.ArduinoCompressedv2
99
98
// AddThing adds a new thing on Arduino IoT Cloud.
100
99
func (cl * client ) AddThing (thing * iotclient.Thing , force bool ) (string , error ) {
101
100
opt := & iotclient.ThingsV2CreateOpts {Force : optional .NewBool (force )}
102
- newThing , resp , err := cl .api .ThingsV2Api .ThingsV2Create (cl .ctx , * thing , opt )
101
+ newThing , _ , err := cl .api .ThingsV2Api .ThingsV2Create (cl .ctx , * thing , opt )
103
102
if err != nil {
104
- var respObj map [string ]interface {}
105
- json .NewDecoder (resp .Body ).Decode (& respObj )
106
- resp .Body .Close ()
107
- return "" , fmt .Errorf ("%s: %s: %v" , "adding new thing" , err , respObj )
103
+ return "" , fmt .Errorf ("%s: %w" , "adding new thing" , errorDetail (err ))
108
104
}
109
105
return newThing .Id , nil
110
106
}
@@ -114,7 +110,7 @@ func (cl *client) UpdateThing(id string, thing *iotclient.Thing, force bool) err
114
110
opt := & iotclient.ThingsV2UpdateOpts {Force : optional .NewBool (force )}
115
111
_ , _ , err := cl .api .ThingsV2Api .ThingsV2Update (cl .ctx , id , * thing , opt )
116
112
if err != nil {
117
- return fmt .Errorf ("%s: %v" , "updating thing" , err )
113
+ return fmt .Errorf ("%s: %v" , "updating thing" , errorDetail ( err ) )
118
114
}
119
115
return nil
120
116
}
@@ -123,7 +119,7 @@ func (cl *client) UpdateThing(id string, thing *iotclient.Thing, force bool) err
123
119
func (cl * client ) DeleteThing (id string ) error {
124
120
_ , err := cl .api .ThingsV2Api .ThingsV2Delete (cl .ctx , id , nil )
125
121
if err != nil {
126
- err = fmt .Errorf ("deleting thing: %w" , err )
122
+ err = fmt .Errorf ("deleting thing: %w" , errorDetail ( err ) )
127
123
return err
128
124
}
129
125
return nil
@@ -134,7 +130,7 @@ func (cl *client) DeleteThing(id string) error {
134
130
func (cl * client ) GetThing (id string ) (* iotclient.ArduinoThing , error ) {
135
131
thing , _ , err := cl .api .ThingsV2Api .ThingsV2Show (cl .ctx , id , nil )
136
132
if err != nil {
137
- err = fmt .Errorf ("retrieving thing, %w" , err )
133
+ err = fmt .Errorf ("retrieving thing, %w" , errorDetail ( err ) )
138
134
return nil , err
139
135
}
140
136
return & thing , nil
@@ -155,7 +151,7 @@ func (cl *client) ListThings(ids []string, device *string, props bool) ([]iotcli
155
151
156
152
things , _ , err := cl .api .ThingsV2Api .ThingsV2List (cl .ctx , opts )
157
153
if err != nil {
158
- err = fmt .Errorf ("retrieving things, %w" , err )
154
+ err = fmt .Errorf ("retrieving things, %w" , errorDetail ( err ) )
159
155
return nil , err
160
156
}
161
157
return things , nil
0 commit comments