mirror of
https://github.com/sasjs/adapter.git
synced 2026-06-08 18:20:20 +00:00
fix(debug): add viya debug log parser - parse JSON from inline blob with webout
This commit is contained in:
@@ -1,18 +1,27 @@
|
||||
import { getValidJson } from './getValidJson'
|
||||
import { parseWeboutResponse } from './parseWeboutResponse'
|
||||
|
||||
/**
|
||||
* When querying a Viya job using the Web approach with _DEBUG=log (used when
|
||||
* runAsTask is true), the webout JSON is inlined into the response via:
|
||||
* var blob = new Blob([`{...}`], {type: 'application/json'});
|
||||
* On abort/error paths the same shape is used but with text/plain and
|
||||
* weboutBEGIN/END markers around the JSON:
|
||||
* var blob = new Blob([`>>weboutBEGIN<<\n{...}\n>>weboutEND<<\n`], {type: 'text/plain'});
|
||||
* No follow-up request is needed — extract and parse the JSON directly.
|
||||
*/
|
||||
export const parseSasViyaLogDebugResponse = async (response: string) => {
|
||||
const blobMatch = response.match(
|
||||
/new Blob\(\[`([\s\S]*?)`\],\s*\{type:\s*'application\/json'\}\)/
|
||||
/new Blob\(\[`([\s\S]*?)`\],\s*\{type:\s*'(?:application\/json|text\/plain)'\}\)/
|
||||
)
|
||||
if (!blobMatch) {
|
||||
throw new Error('Unable to find webout blob in debug log response.')
|
||||
}
|
||||
|
||||
return getValidJson(blobMatch[1])
|
||||
const blobContent = blobMatch[1]
|
||||
const stripped = blobContent.includes('>>weboutBEGIN<<')
|
||||
? parseWeboutResponse(blobContent)
|
||||
: blobContent
|
||||
|
||||
return getValidJson(stripped)
|
||||
}
|
||||
|
||||
@@ -31,6 +31,20 @@ var blob = new Blob([\`{"SYSDATE" : "13MAY26"
|
||||
expect(result).toEqual(resultData)
|
||||
})
|
||||
|
||||
it('should extract and parse JSON wrapped in weboutBEGIN/END (text/plain blob)', async () => {
|
||||
const resultData = { SYSCC: '1012', SYSERRORTEXT: 'File missing.' }
|
||||
const response = `<script>
|
||||
var blob = new Blob([\`>>weboutBEGIN<<
|
||||
${JSON.stringify(resultData)}
|
||||
>>weboutEND<<
|
||||
\`], {type: 'text/plain'});
|
||||
</script>`
|
||||
|
||||
const result = await parseSasViyaLogDebugResponse(response)
|
||||
|
||||
expect(result).toEqual(resultData)
|
||||
})
|
||||
|
||||
it('should throw an error if blob is not found', async () => {
|
||||
const response = `<html><body>No blob here</body></html>`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user