File tree Expand file tree Collapse file tree 3 files changed +63
-8
lines changed Expand file tree Collapse file tree 3 files changed +63
-8
lines changed Original file line number Diff line number Diff line change 2
2
3
3
return [
4
4
// The Torchlight client caches highlighted code blocks. Here
5
- // you can define which cache driver you'd like to use.
5
+ // you can define which cache driver you'd like to use. If
6
+ // leave this blank your default app cache will be used.
6
7
'cache ' => env ('TORCHLIGHT_CACHE_DRIVER ' ),
7
8
8
9
// Which theme you want to use. You can find all of the themes at
9
- // https://torchlight.dev/themes, or you can provide your own .
10
+ // https://torchlight.dev/themes.
10
11
'theme ' => env ('TORCHLIGHT_THEME ' , 'material-theme-palenight ' ),
11
12
12
13
// Your API token from torchlight.dev.
Original file line number Diff line number Diff line change 9
9
use Illuminate \Support \Collection ;
10
10
use Illuminate \Support \Facades \Cache ;
11
11
use Illuminate \Support \Facades \Http ;
12
+ use Throwable ;
12
13
use Torchlight \Exceptions \ConfigurationException ;
13
14
use Torchlight \Exceptions \RequestException ;
14
15
use Torchlight \Exceptions \TorchlightException ;
@@ -45,12 +46,18 @@ protected function request(Collection $blocks)
45
46
46
47
$ host = Torchlight::config ('host ' , 'https://api.torchlight.dev ' );
47
48
48
- $ response = Http::timeout (5 )
49
- ->withToken ($ this ->getToken ())
50
- ->post ($ host . '/highlight ' , [
51
- 'blocks ' => $ this ->blocksAsRequestParam ($ blocks )->values ()->toArray (),
52
- ])
53
- ->json ();
49
+ try {
50
+ $ response = Http::timeout (5 )
51
+ ->withToken ($ this ->getToken ())
52
+ ->post ($ host . '/highlight ' , [
53
+ 'blocks ' => $ this ->blocksAsRequestParam ($ blocks )->values ()->toArray (),
54
+ ])
55
+ ->json ();
56
+ } catch (Throwable $ e ) {
57
+ $ response = [
58
+ 'error ' => $ e ->getMessage ()
59
+ ];
60
+ }
54
61
55
62
$ this ->potentiallyThrowRequestException ($ response );
56
63
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * @author Aaron Francis <[email protected] |https://twitter.com/aarondfrancis>
4
+ */
5
+
6
+ namespace Torchlight \Tests ;
7
+
8
+ use Torchlight \Block ;
9
+ use Torchlight \Exceptions \RequestException ;
10
+ use Torchlight \Torchlight ;
11
+
12
+ class ClientTimeoutTest extends BaseTest
13
+ {
14
+ public function getEnvironmentSetUp ($ app )
15
+ {
16
+ config ()->set ('torchlight ' , [
17
+ 'theme ' => 'material ' ,
18
+ 'token ' => 'token ' ,
19
+ 'bust ' => 0 ,
20
+ 'host ' => 'https://nonexistent.torchlight.dev '
21
+ ]);
22
+ }
23
+
24
+ /** @test */
25
+ public function it_catches_the_connect_exception ()
26
+ {
27
+ // Our exception, not the default Laravel one.
28
+ $ this ->expectException (RequestException::class);
29
+
30
+ Torchlight::highlight (
31
+ Block::make ('id ' )->language ('php ' )->code ('echo "hello world"; ' )
32
+ );
33
+ }
34
+
35
+ /** @test */
36
+ public function it_catches_the_connect_exception_in_prod ()
37
+ {
38
+ Torchlight::overrideEnvironment ('production ' );
39
+
40
+ Torchlight::highlight (
41
+ Block::make ('id ' )->language ('php ' )->code ('echo "hello world"; ' )
42
+ );
43
+
44
+ // Just want to make sure we got past the highlight with no exception.
45
+ $ this ->assertTrue (true );
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments