fix(job-execution): return Internal Server Error code in case of Stored Process Error - #601
fix(job-execution): return Internal Server Error code in case of Stored Process Error#601krishna-acondy wants to merge 1 commit into
Conversation
…red Process Error
Coverage reportTotal coverage
Report generated by 🧪jest coverage report action from 596c1de |
There was a problem hiding this comment.
Hermes Agent Code Review
Verdict: APPROVE (with nits) — the change is correct, minimal, and low-risk. A small documentation/test follow-up is suggested but does not block merge.
Summary
This PR changes the JobExecutionError error code returned by parseError for the "Stored Process Error / This request completed with errors." branch from 404 to 500.
A 404 semantically means Not Found, which is incorrect for a Stored Process that was located and executed but returned an error during execution. 500 (Internal Server Error) is the right status for a server-side execution failure, so this is a correct fix.
Correctness ✅
- The change is a single literal swap (
404→500) atsrc/request/RequestClient.ts:630, matching the surrounding pattern. The adjacent "stored process not found" branch (line 616) correctly keeps404, so the two cases are now semantically distinct and consistent. JobExecutionError(src/types/errors/JobExecutionError.ts) acceptserrorCode: number, so500is type-compatible. The value is stored onthis.errorCodeand surfaced via the error message stringError Code ${errorCode}: ${errorMessage}.- Downstream handlers in
WebJobExecutor,FileUploader, andJesJobExecutorbranch one instanceof JobExecutionError, not on the numericerrorCode, so there is no change to control flow, retry behaviour, or error propagation. Confirmed no code insrc/job-execution/orsrc/request/switches onerrorCode === 404or similar. appendRequestdoes not consumeerrorCode; it only recordslogFile/serviceLink. So the value change has no side effects on request logging.
Security ✅
- No new inputs, no network surface change, no secrets handling. The error code is derived from a static literal, not from untrusted response data (unlike the
responseJson.errorCodebranch which already forwards server-supplied codes). No injection or information-disclosure concern.
Tests ⚠️
src/test/RequestClient.spec.tsdoes not coverparseErrorat all — neither the 404 "not found" branch nor this 500 "Stored Process Error" branch. There are no tests asserting onerrorCodefor anyparseErrorpath.- Suggestion (non-blocking): add a unit test for
parseErrorcovering the "Stored Process Error" HTML payload, asserting that aJobExecutionErrorwitherrorCode === 500is returned. This would lock in the new behaviour and prevent regression. SinceparseErroris not exported, the test could drive it through the publicparseWeboutResponse/request error path or via a small export.
Style ✅
- Change is consistent with the file's existing style. No formatting concerns (prettier would not flag a numeric literal change).
Performance ✅
- No impact — identical runtime cost.
Notes
- The PR is marked Draft and the PR body checkboxes (unit tests / sasjs-tests / Data Controller) are all unchecked. The author should confirm at least
npm testpasses before flipping to ready-for-review, though the one-line nature makes a regression unlikely. - The linked issue (sasjs/cli#1063) motivates returning the correct status code to callers; this change satisfies that intent for the adapter side.
Reviewed by Hermes Agent (GitHub App)
| const log = parts[1].split('<pre>')[1].split('</pre>')[0] | ||
| const message = `This request completed with errors.` | ||
| return new JobExecutionError(404, message, log) | ||
| return new JobExecutionError(500, message, log) |
There was a problem hiding this comment.
Correct fix — 500 is the right code for a Stored Process that ran but errored, while the 404 on line 616 correctly remains for the genuinely-not-found case.
Nit: there are currently no unit tests covering parseError (see src/test/RequestClient.spec.ts). Consider adding a test that feeds a "Stored Process Error ... This request completed with errors. ... <h2>SAS Log</h2><pre>...</pre>" payload and asserts errorCode === 500 so this behaviour is locked in.
Issue
sasjs/cli#1063
Intent
Return the correct error code when there is a SAS Stored Process Error.
Implementation
Changed 404 to 500.
Checks
No PR (that involves a non-trivial code change) should be merged, unless all items below are confirmed! If an urgent fix is needed - use a tar file.
sasjs-cliunit tests are passing (npm test).sasjs-testsare passing (instructions available here).