@@ -47,18 +47,30 @@ describe("throwFetchError", () => {
4747 mockAccountId ( ) ;
4848 mockApiToken ( ) ;
4949 runInTempDir ( ) ;
50- mockConsoleMethods ( ) ;
50+ const std = mockConsoleMethods ( ) ;
5151
52- it ( "should include api errors and messages in error" , async ( ) => {
52+ it ( "should include api errors, messages and documentation_url in error" , async ( ) => {
5353 msw . use (
5454 http . get ( "*/user" , ( ) => {
5555 return HttpResponse . json (
5656 createFetchResult (
5757 null ,
5858 false ,
5959 [
60- { code : 10001 , message : "error one" } ,
61- { code : 10002 , message : "error two" } ,
60+ {
61+ code : 10001 ,
62+ message : "error one" ,
63+ documentation_url : "https://example.com/1" ,
64+ } ,
65+ {
66+ code : 10002 ,
67+ message : "error two" ,
68+ documentation_url : "https://example.com/2" ,
69+ } ,
70+ {
71+ code : 10003 ,
72+ message : "error three" ,
73+ } ,
6274 ] ,
6375 [ "message one" , "message two" ]
6476 )
@@ -68,8 +80,15 @@ describe("throwFetchError", () => {
6880 await expect ( runWrangler ( "whoami" ) ) . rejects . toMatchObject ( {
6981 text : "A request to the Cloudflare API (/user) failed." ,
7082 notes : [
71- { text : "error one [code: 10001]" } ,
72- { text : "error two [code: 10002]" } ,
83+ {
84+ text : "error one [code: 10001]\nTo learn more about this error, visit: https://example.com/1" ,
85+ } ,
86+ {
87+ text : "error two [code: 10002]\nTo learn more about this error, visit: https://example.com/2" ,
88+ } ,
89+ {
90+ text : "error three [code: 10003]" ,
91+ } ,
7392 { text : "message one" } ,
7493 { text : "message two" } ,
7594 {
@@ -79,19 +98,100 @@ describe("throwFetchError", () => {
7998 } ) ;
8099 } ) ;
81100
101+ it ( "nested" , async ( ) => {
102+ msw . use (
103+ http . get ( "*/user" , ( ) => {
104+ return HttpResponse . json (
105+ createFetchResult (
106+ null ,
107+ false ,
108+ [
109+ {
110+ code : 10001 ,
111+ message : "error one" ,
112+ documentation_url : "https://example.com/1" ,
113+ error_chain : [
114+ {
115+ code : 10002 ,
116+ message : "error two" ,
117+ error_chain : [
118+ {
119+ code : 10003 ,
120+ message : "error three" ,
121+ documentation_url : "https://example.com/3" ,
122+ error_chain : [
123+ {
124+ code : 10004 ,
125+ message : "error 4" ,
126+ documentation_url : "https://example.com/4" ,
127+ } ,
128+ ] ,
129+ } ,
130+ ] ,
131+ } ,
132+ ] ,
133+ } ,
134+ ] ,
135+ [ "message one" , "message two" ]
136+ )
137+ ) ;
138+ } )
139+ ) ;
140+ await expect ( runWrangler ( "whoami" ) ) . rejects . toMatchInlineSnapshot (
141+ `[APIError: A request to the Cloudflare API (/user) failed.]`
142+ ) ;
143+
144+ expect ( std . out ) . toMatchInlineSnapshot ( `
145+ "Getting User settings...
146+
147+ [31mX [41;31m[[41;97mERROR[41;31m][0m [1mA request to the Cloudflare API (/user) failed.[0m
148+
149+ error one [code: 10001]
150+ To learn more about this error, visit: [4mhttps://example.com/1[0m
151+
152+ - error two [code: 10002]
153+
154+ - error three [code: 10003]
155+ To learn more about this error, visit: [4mhttps://example.com/3[0m
156+
157+ - error 4 [code: 10004]
158+ To learn more about this error, visit: [4mhttps://example.com/4[0m
159+
160+ message one
161+ message two
162+
163+ If you think this is a bug, please open an issue at:
164+ [4mhttps://github.com/cloudflare/workers-sdk/issues/new/choose[0m
165+
166+ "
167+ ` ) ;
168+ } ) ;
169+
82170 it ( "should include api errors without messages" , async ( ) => {
83171 msw . use (
84172 http . get ( "*/user" , ( ) => {
85173 return HttpResponse . json ( {
86174 result : null ,
87175 success : false ,
88- errors : [ { code : 10000 , message : "error" } ] ,
176+ errors : [
177+ {
178+ code : 10000 ,
179+ message : "error" ,
180+ documentation_url : "https://example.com/1" ,
181+ } ,
182+ { code : 10001 , message : "error 1" } ,
183+ ] ,
89184 } ) ;
90185 } )
91186 ) ;
92187 await expect ( runWrangler ( "whoami" ) ) . rejects . toMatchObject ( {
93188 text : "A request to the Cloudflare API (/user) failed." ,
94- notes : [ { text : "error [code: 10000]" } ] ,
189+ notes : [
190+ {
191+ text : "error [code: 10000]\nTo learn more about this error, visit: https://example.com/1" ,
192+ } ,
193+ { text : "error 1 [code: 10001]" } ,
194+ ] ,
95195 } ) ;
96196 } ) ;
97197} ) ;
0 commit comments