File tree Expand file tree Collapse file tree 4 files changed +84
-1
lines changed Expand file tree Collapse file tree 4 files changed +84
-1
lines changed Original file line number Diff line number Diff line change @@ -334,6 +334,35 @@ exports[`
334334}
335335` ;
336336
337+ exports [`
338+ findFeed(url: "https://non--------existing-domain.com") {
339+ link
340+ }
341+ 1` ] = `
342+ {
343+ " data" : null ,
344+ " errors" : [
345+ {
346+ " extensions" : {
347+ " code" : " dns-lookup-error" ,
348+ " message" : " Could not find domain" ,
349+ " type" : " DnsLookupError" ,
350+ },
351+ " locations" : [
352+ {
353+ " column" : 3 ,
354+ " line" : 2 ,
355+ },
356+ ],
357+ " message" : " Could not find domain" ,
358+ " path" : [
359+ " findFeed" ,
360+ ],
361+ },
362+ ],
363+ }
364+ ` ;
365+
337366exports [`
338367 findFeed(url: "https://rolflekang.com") {
339368 link
@@ -352,3 +381,32 @@ exports[`
352381 },
353382}
354383` ;
384+
385+ exports [`
386+ findFeed(url: "not-a-url") {
387+ link
388+ }
389+ 1` ] = `
390+ {
391+ " data" : null ,
392+ " errors" : [
393+ {
394+ " extensions" : {
395+ " code" : " invalid-url" ,
396+ " message" : " Invalid url" ,
397+ " type" : " InvalidUrlError" ,
398+ },
399+ " locations" : [
400+ {
401+ " column" : 3 ,
402+ " line" : 2 ,
403+ },
404+ ],
405+ " message" : " Invalid url" ,
406+ " path" : [
407+ " findFeed" ,
408+ ],
409+ },
410+ ],
411+ }
412+ ` ;
Original file line number Diff line number Diff line change @@ -62,3 +62,15 @@ testGraphqlApi`
6262 items { title }
6363 }
6464` ;
65+
66+ testGraphqlApi `
67+ findFeed(url: "not-a-url") {
68+ link
69+ }
70+ ` ;
71+
72+ testGraphqlApi `
73+ findFeed(url: "https://non--------existing-domain.com") {
74+ link
75+ }
76+ ` ;
Original file line number Diff line number Diff line change @@ -139,6 +139,14 @@ export class ConnectionFailedError extends BaseError {
139139 }
140140}
141141
142+ export class InvalidUrlError extends BaseError {
143+ url : string ;
144+ constructor ( url : string ) {
145+ super ( "Invalid url" , "invalid-url" ) ;
146+ this . url = url ;
147+ }
148+ }
149+
142150export function createErrorFormatter (
143151 Sentry : any ,
144152) : ApolloServerOptions < any > [ "formatError" ] {
Original file line number Diff line number Diff line change @@ -3,10 +3,11 @@ import type { CheerioAPI } from "cheerio";
33import type { Element , Node } from "domhandler" ;
44import normalizeUrl from "normalize-url" ;
55
6- import { BaseError } from "../errors.js" ;
6+ import { BaseError , InvalidUrlError } from "../errors.js" ;
77import { logger } from "../logger.js" ;
88import request from "../request.js" ;
99import { parseFromQuery , parseFromString } from "./feed.js" ;
10+ import isUrl from "is-url" ;
1011
1112type FindFeedResponse = {
1213 title : string ;
@@ -93,6 +94,10 @@ export async function findFeed({
9394 url : string ;
9495 normalize ?: boolean ;
9596} ) : Promise < FindFeedResponse [ ] > {
97+ if ( ! isUrl ( url ) ) {
98+ throw new InvalidUrlError ( url ) ;
99+ }
100+
96101 const normalizedUrl = normalize ? url : normalizeUrl ( url , normalizeOptions ) ;
97102
98103 if ( ! normalizedUrl ) {
You can’t perform that action at this time.
0 commit comments