@@ -219,19 +219,9 @@ describe("withFxaUser", () => {
219219 outcome : "introspection-error" ,
220220 endpoint : ENDPOINT ,
221221 httpStatus,
222- errorClass : "FxaIntrospectError" ,
223222 } ,
224223 fingerprint : [ "firefox-api-fxa-introspect" ] ,
225224 } ) ;
226- expect ( logger . error ) . toHaveBeenCalledWith ( "firefox_api_error" , {
227- outcome : "introspection-error" ,
228- endpoint : ENDPOINT ,
229- httpStatus,
230- errorClass : "FxaIntrospectError" ,
231- fingerprint : [ "firefox-api-fxa-introspect" ] ,
232- errorMessage : `FxA introspect returned ${ httpStatus } ` ,
233- stack : error . stack ,
234- } ) ;
235225 expect ( handler ) . not . toHaveBeenCalled ( ) ;
236226 } ,
237227 ) ;
@@ -256,11 +246,7 @@ describe("withFxaUser", () => {
256246 expect ( Sentry . captureException ) . toHaveBeenCalledWith (
257247 new Error ( "FxA introspect returned a malformed body" ) ,
258248 {
259- tags : {
260- outcome : "introspection-error" ,
261- endpoint : ENDPOINT ,
262- errorClass : "Error" ,
263- } ,
249+ tags : { outcome : "introspection-error" , endpoint : ENDPOINT } ,
264250 fingerprint : [ "firefox-api-fxa-introspect" ] ,
265251 } ,
266252 ) ;
@@ -280,11 +266,7 @@ describe("withFxaUser", () => {
280266 expect ( Sentry . captureException ) . toHaveBeenCalledWith (
281267 expect . anything ( ) ,
282268 expect . objectContaining ( {
283- tags : {
284- outcome : "introspection-error" ,
285- endpoint : ENDPOINT ,
286- errorClass : "TimeoutError" ,
287- } ,
269+ tags : { outcome : "introspection-error" , endpoint : ENDPOINT } ,
288270 } ) ,
289271 ) ;
290272 } ) ;
@@ -305,11 +287,7 @@ describe("withFxaUser", () => {
305287 CLIENT_ID ,
306288 ) ;
307289 expect ( Sentry . captureException ) . toHaveBeenCalledWith ( new Error ( "boom" ) , {
308- tags : {
309- endpoint : ENDPOINT ,
310- outcome : "lookup-error" ,
311- errorClass : "Error" ,
312- } ,
290+ tags : { endpoint : ENDPOINT , outcome : "lookup-error" } ,
313291 } ) ;
314292 // Before the handler, so the auth counter has it
315293 expect ( incFirefoxApiHandlerResponse ) . not . toHaveBeenCalled ( ) ;
@@ -331,11 +309,7 @@ describe("withFxaUser", () => {
331309 CLIENT_ID ,
332310 ) ;
333311 expect ( Sentry . captureException ) . toHaveBeenCalledWith ( new Error ( "boom" ) , {
334- tags : {
335- endpoint : ENDPOINT ,
336- outcome : "handler-error" ,
337- errorClass : "Error" ,
338- } ,
312+ tags : { endpoint : ENDPOINT , outcome : "handler-error" } ,
339313 } ) ;
340314 expect ( incFirefoxApiHandlerResponse ) . toHaveBeenCalledWith (
341315 ENDPOINT ,
@@ -345,44 +319,20 @@ describe("withFxaUser", () => {
345319 } ) ;
346320 } ) ;
347321
348- describe ( "error log" , ( ) => {
349- it ( "keeps message and stack on the log" , async ( ) => {
350- mockIntrospection ( ) ;
351- vi . mocked ( getSubscriberByFxaUid ) . mockResolvedValue ( subscriber ) ;
352- const error = new TypeError ( "boom" ) ;
353- handler . mockRejectedValueOnce ( error ) ;
354-
355- await gated ( authed ( ) ) ;
356-
357- expect ( logger . error ) . toHaveBeenCalledWith ( "firefox_api_error" , {
358- endpoint : ENDPOINT ,
359- outcome : "handler-error" ,
360- errorClass : "TypeError" ,
361- fingerprint : undefined ,
362- errorMessage : "boom" ,
363- stack : error . stack ,
364- } ) ;
365- } ) ;
366-
367- it ( "handles a thrown non-Error" , async ( ) => {
368- mockIntrospection ( ) ;
369- vi . mocked ( getSubscriberByFxaUid ) . mockResolvedValue ( subscriber ) ;
370- handler . mockRejectedValueOnce ( "boom" ) ;
322+ it ( "logs the error message and stack" , async ( ) => {
323+ mockIntrospection ( ) ;
324+ vi . mocked ( getSubscriberByFxaUid ) . mockResolvedValue ( subscriber ) ;
325+ const error = new TypeError ( "boom" ) ;
326+ handler . mockRejectedValueOnce ( error ) ;
371327
372- const res = await gated ( authed ( ) ) ;
328+ await gated ( authed ( ) ) ;
373329
374- expect ( res . status ) . toBe ( 500 ) ;
375- expect ( Sentry . captureException ) . toHaveBeenCalledWith ( "boom" , {
376- tags : {
377- endpoint : ENDPOINT ,
378- outcome : "handler-error" ,
379- errorClass : "string" ,
380- } ,
381- } ) ;
382- expect ( logger . error ) . toHaveBeenCalledWith (
383- "firefox_api_error" ,
384- expect . objectContaining ( { errorMessage : "boom" , stack : undefined } ) ,
385- ) ;
330+ expect ( logger . error ) . toHaveBeenCalledExactlyOnceWith ( "firefox_api_error" , {
331+ endpoint : ENDPOINT ,
332+ outcome : "handler-error" ,
333+ errorClass : "TypeError" ,
334+ errorMessage : "boom" ,
335+ stack : error . stack ,
386336 } ) ;
387337 } ) ;
388338
@@ -407,7 +357,6 @@ describe("withFxaUser", () => {
407357 reason : "http-error" ,
408358 endpoint : ENDPOINT ,
409359 httpStatus : 502 ,
410- errorClass : "UpstreamUnavailableError" ,
411360 } ,
412361 fingerprint : [ "firefox-api-hibp-unavailable" ] ,
413362 } ) ;
@@ -543,11 +492,7 @@ describe("withFxaUser", () => {
543492 expect ( Sentry . captureException ) . toHaveBeenCalledWith (
544493 expect . any ( Error ) ,
545494 {
546- tags : {
547- outcome : "redis-error" ,
548- endpoint : ENDPOINT ,
549- errorClass : "Error" ,
550- } ,
495+ tags : { outcome : "redis-error" , endpoint : ENDPOINT } ,
551496 fingerprint : [ "firefox-api-rate-limit-redis" ] ,
552497 } ,
553498 ) ;
0 commit comments