File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,12 @@ export class InvalidUrlError extends BaseError {
147147 }
148148}
149149
150+ export class CloudflareBlockError extends BaseError {
151+ constructor ( ) {
152+ super ( "Blocked by cloudflare" , "cloudflare-block" ) ;
153+ }
154+ }
155+
150156export function createErrorFormatter (
151157 Sentry : any ,
152158) : ApolloServerOptions < any > [ "formatError" ] {
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import _debug from "debug";
44const debug = _debug ( "graphql-rss-parser:request" ) ;
55
66import {
7+ CloudflareBlockError ,
78 ConnectionRefusedError ,
89 DnsLookupError ,
910 EmptyHttpResponseError ,
@@ -43,6 +44,15 @@ export default async function request(url: string) {
4344 } catch ( error : any ) {
4445 debug ( `request to ${ url } failed with error` , error ) ;
4546 if ( error . response ?. status ) {
47+ if ( error . response ?. status === 403 ) {
48+ const text = error . response . data . toString ( ) ;
49+ if (
50+ text . includes ( "Enable JavaScript and cookies to continue" ) &&
51+ text . includes ( "_cf_" )
52+ ) {
53+ throw new CloudflareBlockError ( ) ;
54+ }
55+ }
4656 throw new UpstreamHttpError ( "Upstream HTTP error" , error . response . status ) ;
4757 }
4858 if ( error . code === "ENOTFOUND" || error . code === "EAI_AGAIN" ) {
You can’t perform that action at this time.
0 commit comments