File tree Expand file tree Collapse file tree 3 files changed +12
-6
lines changed Expand file tree Collapse file tree 3 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -42,13 +42,11 @@ export default class Client {
4242
4343 async request ( path , options = { } ) {
4444 try {
45- const fetchOptions = {
45+ const response = await fetch ( this . baseURL + path , {
4646 headers : this . headers ,
4747 timeout : this . timeout ,
4848 ...options ,
49- } ;
50-
51- const response = await fetch ( this . baseURL + path , fetchOptions ) ;
49+ } ) ;
5250
5351 if ( ! response . ok ) {
5452 throw new Error ( await response . text ( ) ) ;
Original file line number Diff line number Diff line change 11class DetectLanguageError extends Error { }
22
33function handleError ( error ) {
4- const message = error ?. response ?. data ?. error ?. message || error . message ;
4+ let message ;
5+
6+ try {
7+ const json = JSON . parse ( error . message ) ;
8+ message = json ?. error ?. message || error . message ;
9+ } catch ( e ) {
10+ message = error . message ;
11+ }
12+
513 const apiError = new DetectLanguageError ( message ) ;
614
715 apiError . stack = error . stack ;
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ describe('detect', () => {
2626 expect ( result [ 0 ] . score ) . to . be . a ( 'number' ) ;
2727 } ) ;
2828
29- it ( 'detects language ' , async ( ) => {
29+ it ( 'fails with invalid API key ' , async ( ) => {
3030 detectLanguage = new DetectLanguage ( 'invalid' ) ;
3131
3232 await expect ( detectLanguage . detect ( 'hello' ) ) . to . be . rejectedWith ( 'Invalid API key' ) ;
You can’t perform that action at this time.
0 commit comments