File tree Expand file tree Collapse file tree 2 files changed +52
-3
lines changed Expand file tree Collapse file tree 2 files changed +52
-3
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import createClient, { ParseAs } from 'openapi-fetch';
44import base32Decode from 'base32-decode' ;
55import { API_KEY_PAK_PREFIX , USER_AGENT } from '../constants.js' ;
66import { getApiKeyInformation } from './getApiKeyInformation.js' ;
7- import { debug } from '../utils/logger.js' ;
7+ import { debug , isDebugEnabled } from '../utils/logger.js' ;
88import { errorFromLoadable } from './errorFromLoadable.js' ;
99
1010async function parseResponse ( response : Response , parseAs : ParseAs ) {
@@ -78,8 +78,18 @@ export function createApiClient({
7878 debug ( `[HTTP] Requesting: ${ request . method } ${ request . url } ` ) ;
7979 } ,
8080 onResponse : async ( { response, options } ) => {
81- debug ( `[HTTP] Response: ${ response . url } [${ response . status } ]` ) ;
82-
81+ let responseText = `[HTTP] Response: ${ response . url } [${ response . status } ]` ;
82+ const apiVersion = response . headers . get ( 'x-tolgee-version' ) ;
83+ if ( apiVersion ) {
84+ responseText += ` [${ response . headers . get ( 'x-tolgee-version' ) } ]` ;
85+ }
86+ if ( ! response . ok && isDebugEnabled ( ) ) {
87+ const clonedBody = await response . clone ( ) . text ( ) ;
88+ if ( clonedBody ) {
89+ responseText += ` [${ clonedBody } ]` ;
90+ }
91+ }
92+ debug ( responseText ) ;
8393 if ( autoThrow && ! response . ok ) {
8494 const loadable = await parseResponse ( response , options . parseAs ) ;
8595 throw new Error (
Original file line number Diff line number Diff line change 1+ import { tmpdir } from 'os' ;
2+ import { join } from 'path' ;
3+ import { rm } from 'fs/promises' ;
4+ import { run } from './utils/run.js' ;
5+ import { TolgeeClient } from '#cli/client/TolgeeClient.js' ;
6+ import { PROJECT_1 } from './utils/api/project1.js' ;
7+ import { createProjectWithClient , deleteProject } from './utils/api/common.js' ;
8+ import { removeTmpFolder } from './utils/tmp.js' ;
9+
10+ const AUTH_FILE_PATH = join ( tmpdir ( ) , '.tolgee-e2e' , 'authentication.json' ) ;
11+
12+ afterEach ( async ( ) => {
13+ await removeTmpFolder ( ) ;
14+ try {
15+ await rm ( AUTH_FILE_PATH ) ;
16+ } catch ( e : any ) {
17+ if ( e . code !== 'ENOENT' ) {
18+ throw e ;
19+ }
20+ }
21+ } ) ;
22+
23+ let client : TolgeeClient ;
24+
25+ describe ( 'Testing error message' , ( ) => {
26+ beforeAll ( async ( ) => {
27+ client = await createProjectWithClient ( 'Project 1' , PROJECT_1 ) ;
28+ } ) ;
29+ afterAll ( async ( ) => {
30+ await deleteProject ( client ) ;
31+ } ) ;
32+
33+ it ( 'error server response body is printed' , async ( ) => {
34+ const out = await run ( [ 'login' , 'tgpat_meow' , '--verbose' ] ) ;
35+
36+ expect ( out . code ) . toBe ( 1 ) ;
37+ expect ( out . stdout ) . toMatch ( '"code":"invalid_pat"' ) ;
38+ } ) ;
39+ } ) ;
You can’t perform that action at this time.
0 commit comments