File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99 httpSubscriptionLink ,
1010 retryLink ,
1111 splitLink ,
12+ TRPCClientError ,
1213} from "@trpc/client" ;
1314import { Spinner } from "@std/cli/unstable-spinner" ;
1415import { error } from "./util.ts" ;
@@ -35,8 +36,10 @@ export function createTrpcClient(deployUrl: string) {
3536 return createTRPCClient < any > ( {
3637 links : [
3738 retryLink ( {
38- retry ( ) {
39- // TODO: check its an auth error
39+ retry ( { error } ) {
40+ if ( error . message !== "Unauthorized" ) {
41+ return false ;
42+ }
4043
4144 if ( typeof retryPromise !== "undefined" ) {
4245 return false ;
@@ -54,6 +57,18 @@ export function createTrpcClient(deployUrl: string) {
5457 condition : ( op ) => op . type === "subscription" ,
5558 false : httpBatchStreamLink ( {
5659 url : deployUrl + "/api" ,
60+ fetch : async ( url , options ) => {
61+ // deno-lint-ignore no-explicit-any
62+ const response = await fetch ( url , options as any ) ;
63+ if ( response . status === 401 ) {
64+ throw TRPCClientError . from ( {
65+ message : "Unauthorized" ,
66+ code : - 32004 ,
67+ data : { httpStatus : 401 , code : "NOT_AUTHENTICATED" } ,
68+ } ) ;
69+ }
70+ return response ;
71+ } ,
5772 async headers ( ) {
5873 if ( retryPromise ) {
5974 await retryPromise ;
@@ -133,8 +148,6 @@ export async function interactive(deployUrl: string): Promise<
133148 Deno . exit ( 1 ) ;
134149 }
135150
136- console . log ( `${ deployUrl } /auth/interactive` ) ;
137-
138151 const body = await res . json ( ) ;
139152
140153 return {
You can’t perform that action at this time.
0 commit comments