1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-02 10:10:06 +00:00

feat(request-client): made verbose mode easier to configure

This commit is contained in:
Yury Shkoda
2023-07-31 16:34:09 +03:00
parent f1e1b33571
commit ea4b30d6ef
4 changed files with 35 additions and 6 deletions

View File

@@ -151,7 +151,11 @@ The `request()` method also has optional parameters such as a config object and
The response object will contain returned tables and columns. Table names are always lowercase, and column names uppercase.
The adapter will also cache the logs (if debug enabled) and even the work tables. For performance, it is best to keep debug mode off.
The adapter will also cache the logs (if debug enabled) and even the work tables. For performance, it is best to keep debug mode off.
### Verbose Mode
Enabling debug will also enable a verbose mode that logs a summary of every HTTP response. Verbose mode can be disabled by calling `disableVerboseMode` method or enabled by `enableVerboseMode` method. Verbose mode can also be enabled/disabled by `startComputeJob` method.
### Session Manager
@@ -272,7 +276,7 @@ Configuration on the client side involves passing an object on startup, which ca
* `appLoc` - this is the folder (eg in metadata or SAS Drive) under which the SAS services are created.
* `serverType` - either `SAS9`, `SASVIYA` or `SASJS`. The `SASJS` server type is for use with [sasjs/server](https://github.com/sasjs/server).
* `serverUrl` - the location (including http protocol and port) of the SAS Server. Can be omitted, eg if serving directly from the SAS Web Server, or in streaming mode.
* `debug` - if `true` then SAS Logs and extra debug information is returned.
* `debug` - if `true` then SAS Logs and extra debug information is returned. Setting debug to true will also enable a verbose mode that will log every HTTP response summary.
* `loginMechanism` - either `Default` or `Redirected`. See [SAS Logon](#sas-logon) section.
* `useComputeApi` - Only relevant when the serverType is `SASVIYA`. If `true` the [Compute API](#using-the-compute-api) is used. If `false` the [JES API](#using-the-jes-api) is used. If `null` or `undefined` the [Web](#using-jes-web-app) approach is used.
* `contextName` - Compute context on which the requests will be called. If missing or not provided, defaults to `Job Execution Compute context`.

View File

@@ -31,6 +31,7 @@ import {
} from './job-execution'
import { ErrorResponse } from './types/errors'
import { LoginOptions, LoginResult } from './types/Login'
import { AxiosResponse } from 'axios'
interface ExecuteScriptParams {
linesOfCode: string[]
@@ -880,7 +881,7 @@ export default class SASjs {
}
if (verboseMode) this.requestClient?.enableVerboseMode()
else this.requestClient?.disableVerboseMode()
else if (verboseMode === false) this.requestClient?.disableVerboseMode()
return this.sasViyaApiClient?.executeComputeJob(
sasJob,
@@ -975,7 +976,8 @@ export default class SASjs {
this.requestClient = new RequestClientClass(
this.sasjsConfig.serverUrl,
this.sasjsConfig.httpsAgentOptions,
this.sasjsConfig.requestHistoryLimit
this.sasjsConfig.requestHistoryLimit,
this.sasjsConfig.debug // enable verbose mode if debug is true
)
} else {
this.requestClient.setConfig(
@@ -1139,4 +1141,23 @@ export default class SASjs {
)
}
}
/**
* Enables verbose mode that will log a summary of every HTTP response.
* @param successCallBack - function that should be triggered on every HTTP response with the status 2**.
* @param errorCallBack - function that should be triggered on every HTTP response with the status different from 2**.
*/
public enableVerboseMode(
successCallBack?: (response: AxiosResponse) => AxiosResponse,
errorCallBack?: (response: AxiosResponse) => AxiosResponse
) {
this.requestClient?.enableVerboseMode(successCallBack, errorCallBack)
}
/**
* Turns off verbose mode to log every HTTP response.
*/
public disableVerboseMode() {
this.requestClient?.disableVerboseMode()
}
}

View File

@@ -233,7 +233,8 @@ export default class SASjs {
this.requestClient = new RequestClient(
this.sasjsConfig.serverUrl,
this.sasjsConfig.httpsAgentOptions,
this.sasjsConfig.requestHistoryLimit
this.sasjsConfig.requestHistoryLimit,
this.sasjsConfig.debug // enable verbose mode if debug is true
)
} else {
this.requestClient.setConfig(

View File

@@ -69,11 +69,14 @@ export class RequestClient implements HttpClient {
constructor(
protected baseUrl: string,
httpsAgentOptions?: https.AgentOptions,
requestsLimit?: number
requestsLimit?: number,
verboseMode?: boolean
) {
this.createHttpClient(baseUrl, httpsAgentOptions)
if (requestsLimit) this.requestsLimit = requestsLimit
if (verboseMode) this.enableVerboseMode()
}
public setConfig(baseUrl: string, httpsAgentOptions?: https.AgentOptions) {