@@ -100,7 +100,7 @@ public function create($data)
100
100
$ item ->setData ($ data )->save ();
101
101
return json_encode ($ item ->getData ());
102
102
} catch (\Exception $ e ) {
103
- return false ;
103
+ return $ this -> getError ( $ e -> getMessage ()) ;
104
104
}
105
105
}
106
106
@@ -118,7 +118,7 @@ public function update($id, $data)
118
118
$ item ->load ($ id );
119
119
120
120
if (!$ item ->getId ()) {
121
- return false ;
121
+ return $ this -> getError ( ' Item not found ' ) ;
122
122
}
123
123
$ data = json_decode ($ data , true );
124
124
foreach ($ this ->_imagesMap as $ key ) {
@@ -133,7 +133,7 @@ public function update($id, $data)
133
133
$ item ->addData ($ data )->save ();
134
134
return json_encode ($ item ->getData ());
135
135
} catch (\Exception $ e ) {
136
- return false ;
136
+ return $ this -> getError ( $ e -> getMessage ()) ;
137
137
}
138
138
}
139
139
@@ -152,9 +152,9 @@ public function delete($id)
152
152
$ item ->delete ();
153
153
return true ;
154
154
}
155
- return false ;
155
+ return $ this -> getError ( ' Something went wrong ' ) ;
156
156
} catch (\Exception $ e ) {
157
- return false ;
157
+ return $ this -> getError ( $ e -> getMessage ()) ;
158
158
}
159
159
}
160
160
@@ -171,11 +171,11 @@ public function get($id)
171
171
$ item ->load ($ id );
172
172
173
173
if (!$ item ->getId ()) {
174
- return false ;
174
+ return $ this -> getError ( ' Item not found ' ) ;
175
175
}
176
176
return json_encode ($ item ->getData ());
177
177
} catch (\Exception $ e ) {
178
- return false ;
178
+ return $ this -> getError ( $ e -> getMessage ()) ;
179
179
}
180
180
}
181
181
@@ -193,12 +193,12 @@ public function view($id, $storeId)
193
193
$ item ->getResource ()->load ($ item , $ id );
194
194
195
195
if (!$ item ->isVisibleOnStore ($ storeId )) {
196
- return false ;
196
+ return $ this -> getError ( ' Item is not visible on this store. ' ) ;
197
197
}
198
198
199
199
return json_encode ($ this ->getDynamicData ($ item ));
200
200
} catch (\Exception $ e ) {
201
- return false ;
201
+ return $ this -> getError ( $ e -> getMessage ()) ;
202
202
}
203
203
}
204
204
@@ -207,4 +207,16 @@ public function view($id, $storeId)
207
207
* @return mixed
208
208
*/
209
209
abstract protected function getDynamicData ($ item );
210
+
211
+ /**
212
+ * @param $massage
213
+ * @return false|string
214
+ */
215
+ public function getError ($ massage ) {
216
+ $ data = ['error ' => 'true ' ];
217
+
218
+ $ data ['message ' ] = $ massage ?? '' ;
219
+
220
+ return json_encode ($ data );
221
+ }
210
222
}
0 commit comments