This repository was archived by the owner on Jun 18, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +45
-8
lines changed
Expand file tree Collapse file tree 3 files changed +45
-8
lines changed Original file line number Diff line number Diff line change @@ -114,15 +114,20 @@ namespace arangodb { namespace fuerte { namespace php {
114114 auto response = new Response (*result);
115115
116116 bool failure = false ;
117- if (response->getFuerteResponse ()->slices ().front ().isObject ()) {
117+
118+ if (response->getFuerteResponse ()->slices ().front ().isObject ()
119+ && response->getFuerteResponse ()->slices ().front ().hasKey (" error" )
120+ ) {
118121 failure = response->getFuerteResponse ()->slices ().front ().get (" error" ).getBool ();
119122 }
120123
121124 auto statusCode = response->getHttpCode ();
122125 if ((!(statusCode >= 200 && statusCode <= 299 )) || failure) {
123126 std::string errorMessage = " Response contains an error" ;
124127
125- if (response->getFuerteResponse ()->slices ().front ().isObject ()) {
128+ if (response->getFuerteResponse ()->slices ().front ().isObject ()
129+ && response->getFuerteResponse ()->slices ().front ().hasKey (" errorMessage" )
130+ ) {
126131 errorMessage = response->getFuerteResponse ()->slices ().front ().get (" errorMessage" ).copyString ();
127132 }
128133
Original file line number Diff line number Diff line change @@ -24,13 +24,26 @@ namespace arangodb { namespace fuerte { namespace php {
2424 Response* response = this ->connection ->sendRequest (&request);
2525 this ->response = response;
2626
27- if (this ->response ->getFuerteResponse ()->slices ().front ().get (" error" ).getBool ()) {
28- ARANGODB_THROW (
29- RuntimeException (),
30- (" Error while executing query in %s on line %d: " +
31- this ->response ->getFuerteResponse ()->slices ().front ().get (" errorMessage" ).copyString ()).c_str ()
32- );
27+ bool failure = false ;
3328
29+ if (this ->response ->getFuerteResponse ()->slices ().front ().isObject ()
30+ && this ->response ->getFuerteResponse ()->slices ().front ().hasKey (" error" )
31+ ) {
32+ failure = this ->response ->getFuerteResponse ()->slices ().front ().get (" error" ).getBool ();
33+ }
34+
35+ auto statusCode = this ->response ->getHttpCode ();
36+
37+ if ((!(statusCode >= 200 && statusCode <= 299 )) || failure) {
38+ std::string errorMessage = " Response contains an error" ;
39+
40+ if (this ->response ->getFuerteResponse ()->slices ().front ().isObject ()
41+ && this ->response ->getFuerteResponse ()->slices ().front ().hasKey (" errorMessage" )
42+ ) {
43+ errorMessage = this ->response ->getFuerteResponse ()->slices ().front ().get (" errorMessage" ).copyString ();
44+ }
45+
46+ throwRequestFailedException (errorMessage.c_str (), statusCode, this ->response ->getBody ());
3447 return ;
3548 }
3649
Original file line number Diff line number Diff line change @@ -247,4 +247,23 @@ public function it_rewinds_cursor_half_way_through()
247247 $ this ->assertCount (100 , $ dataSet2 );
248248 $ this ->assertSame ($ dataSet1 , \array_slice ($ dataSet2 , 0 , 50 ));
249249 }
250+
251+ /**
252+ * @test
253+ */
254+ public function it_throws_exception_if_collection_not_found ()
255+ {
256+ $ collection = 'event_streams ' ;
257+ $ this ->connection = TestUtil::getConnection ();
258+
259+ $ this ->expectException (\ArangoDb \RequestFailedException::class);
260+
261+ $ cursor = $ this ->connection ->query (Vpack::fromArray ([
262+ 'query ' => 'FOR c IN @@collection RETURN c ' ,
263+ 'bindVars ' => ['@collection ' => $ collection ]
264+ ]));
265+
266+ $ cursor ->rewind ();
267+ $ iterations = 0 ;
268+ }
250269}
You can’t perform that action at this time.
0 commit comments