File tree Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,45 @@ describe("Client.ts", () => {
101101 const response = await client . api ( "me" ) . get ( ) ;
102102 assert . equal ( response , responseBody ) ;
103103 } ) ;
104+
105+ it ( "Should throw error in case the access token is undefined" , async ( ) => {
106+ try {
107+ const options = {
108+ defaultVersion : "v1.0" ,
109+ debugLogging : true ,
110+ authProvider : ( done ) => {
111+ done ( null , getTokenFunction ( ) ) ;
112+ } ,
113+ } ;
114+
115+ const getTokenFunction = ( ) : string => {
116+ return undefined ;
117+ } ;
118+ const client = Client . init ( options ) ;
119+ const res = await client . api ( "/test" ) . get ( ) ;
120+ } catch ( error ) {
121+ assert . isDefined ( error . body ) ;
122+ }
123+ } ) ;
124+
125+ it ( "Should throw error in case the access token is empty" , async ( ) => {
126+ try {
127+ const options = {
128+ defaultVersion : "v1.0" ,
129+ debugLogging : true ,
130+ authProvider : ( done ) => {
131+ done ( null , getTokenFunction ( ) ) ;
132+ } ,
133+ } ;
134+ const getTokenFunction = ( ) : string => {
135+ return "" ;
136+ } ;
137+ const client = Client . init ( options ) ;
138+ const res = await client . api ( "/test" ) . get ( ) ;
139+ } catch ( error ) {
140+ assert . isDefined ( error . body ) ;
141+ }
142+ } ) ;
104143 } ) ;
105144
106145 describe ( "init" , ( ) => {
Original file line number Diff line number Diff line change 99 * @module CustomAuthenticationProvider
1010 */
1111
12+ import { GraphError } from "./browser" ;
1213import { AuthenticationProvider } from "./IAuthenticationProvider" ;
1314import { AuthProvider } from "./IAuthProvider" ;
1415
@@ -48,7 +49,7 @@ export class CustomAuthenticationProvider implements AuthenticationProvider {
4849 resolve ( accessToken ) ;
4950 } else {
5051 if ( ! error ) {
51- reject ( "Access token cannot be undefined or empty" ) ;
52+ error = new GraphError ( - 1 , "Access token cannot be undefined or empty. " ) ;
5253 }
5354 reject ( error ) ;
5455 }
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ export class GraphErrorHandler {
5959 */
6060 private static constructErrorFromResponse ( error : any , statusCode : number ) : GraphError {
6161 if ( ! error . error ) {
62- const graphError = new GraphError ( statusCode , "SDK failed to send the request" ) ;
62+ const graphError = new GraphError ( statusCode , "Microsoft Graph JavaScript Client SDK came across an error while processing the request" ) ;
6363 graphError . body = error ;
6464 return graphError ;
6565 }
You can’t perform that action at this time.
0 commit comments