File tree 2 files changed +35
-7
lines changed
2 files changed +35
-7
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,26 @@ export async function getHostingService(
26
26
) : Promise < HostingService > {
27
27
const hostname = aliases ?. [ fetchURL . hostname ] ?? fetchURL . hostname ;
28
28
const svcName = hostname . replace ( / \W / g, "_" ) ;
29
- const svc = await import (
30
- new URL ( `./services/${ svcName } .ts` , import . meta. url ) . href
31
- ) ;
32
- return svc . service ;
29
+ try {
30
+ const svc = await import (
31
+ new URL ( `./services/${ svcName } .ts` , import . meta. url ) . href
32
+ ) ;
33
+ return svc . service ;
34
+ } catch ( err : unknown ) {
35
+ if ( err instanceof TypeError ) {
36
+ // TypeError: Module not found "...".
37
+ throw new UnsupportedHostingServiceError ( hostname , svcName ) ;
38
+ }
39
+ throw err ;
40
+ }
41
+ }
42
+
43
+ export class UnsupportedHostingServiceError extends Error {
44
+ constructor (
45
+ public hostname : string ,
46
+ public svcName : string ,
47
+ ) {
48
+ super ( `Unsupported hosting service: ${ hostname } (${ svcName } )` ) ;
49
+ this . name = this . constructor . name ;
50
+ }
33
51
}
Original file line number Diff line number Diff line change 1
- import { assertSnapshot } from "https://deno.land/[email protected] /testing/snapshot.ts" ;
2
- import { getHostingService } from "./mod.ts" ;
1
+ import { assertRejects } from "https://deno.land/[email protected] /assert/mod.ts" ;
2
+ import { assertSnapshot } from "https://deno.land/[email protected] /testing/snapshot.ts" ;
3
+ import { getHostingService , UnsupportedHostingServiceError } from "./mod.ts" ;
3
4
4
5
Deno . test ( "getHostingService" , async ( t ) => {
6
+ await t . step ( "throws error for unsupported hosting service" , async ( ) => {
7
+ const url = new URL ( "https://example.com/lambdalisue/gin.vim" ) ;
8
+ await assertRejects (
9
+ ( ) => {
10
+ return getHostingService ( url ) ;
11
+ } ,
12
+ UnsupportedHostingServiceError ,
13
+ ) ;
14
+ } ) ;
15
+
5
16
const urls = [
6
17
new URL ( "ssh://[email protected] /lambdalisue/gin.vim" ) ,
7
18
new URL ( "https://github.com/lambdalisue/gin.vim" ) ,
8
19
] ;
9
-
10
20
for ( const url of urls ) {
11
21
const svc = await getHostingService ( url ) ;
12
22
You can’t perform that action at this time.
0 commit comments