Skip to content

Commit

Permalink
fix: named response is only set, if all testResults are valid
Browse files Browse the repository at this point in the history
  • Loading branch information
AnWeber committed Oct 29, 2024
1 parent 498fa39 commit c7d9f78
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 23 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
## [6.16.2] (2024-10-29)

### Fix
- named response is only set, if all testResults are valid

## [6.16.1] ( 2024-10-29)

### Fix
- support `http_proxy` environment variable
- support `https_proxy` environment variable
- support html mimetype for dom parser and use only valid mimetype in parseFromString


## [6.16.0] ( 2024-10-28)
### Features
- support client certificates on OAuth2 Requests (#802)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"publisher": "AnWeber",
"description": "HTTP/REST CLI Client for *.http files",
"version": "6.16.1",
"version": "6.16.2",
"homepage": "https://github.com/AnWeber/httpyac",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions src/plugins/core/execute/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './createRequestInterceptor';
export * from './lazyVariableInterceptor';
export * from './logResponseInterceptor';
export * from './metaDataNameInterceptor';
export * from './processedHttpRegionInterceptor';
export * from './regionScopedVariablesInterceptor';
37 changes: 37 additions & 0 deletions src/plugins/core/execute/metaDataNameInterceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as models from '../../../models';
import * as utils from '../../../utils';

import { HookInterceptor, HookTriggerContext } from 'hookpoint';

export class MetaDataNameInterceptor implements HookInterceptor<[models.ProcessorContext], boolean | void> {
id = 'metaDataName';
async afterLoop(
hookContext: HookTriggerContext<[models.ProcessorContext], boolean | undefined>
): Promise<boolean | undefined> {
const context = hookContext.args[0];
if (!context.httpRegion.response || !utils.isString(context.httpRegion.metaData.name)) {
return true;
}

if (
context.httpRegion.testResults &&
context.httpRegion.testResults.some(t => t.status !== models.TestResultStatus.SUCCESS)
) {
return true;
}

const name = context.httpRegion.metaData.name
.trim()
.replace(/\s/gu, '-')
.replace(/-./gu, value => value[1].toUpperCase());
utils.setVariableInContext(
{
[name]: context.httpRegion.response.parsedBody || context.httpRegion.response.body,
[`${name}Response`]: context.httpRegion.response,
},
context
);

return true;
}
}
2 changes: 1 addition & 1 deletion src/plugins/core/registerCorePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function initOnRequestHook(api: models.HttpyacHooksApi) {
}

function initOnResponseHook(api: models.HttpyacHooksApi) {
api.hooks.onResponse.addHook('handleMetaDataName', response.handleNameMetaData);
api.hooks.onResponse.addHook('setLastResponseInVariables', response.setLastResponseInVariables);
api.hooks.onResponse.addInterceptor(response.jsonResponseInterceptor);
}
Expand Down Expand Up @@ -95,6 +94,7 @@ function initExecuteInterceptor(api: models.HttpyacHooksApi) {
api.hooks.responseLogging.addInterceptor(processedHttpRegionInterceptor.getResponseLoggingInterceptor());
api.hooks.execute.addInterceptor(new execute.CreateRequestInterceptor());
api.hooks.execute.addInterceptor(new execute.LazyVariableInterceptor());
api.hooks.execute.addInterceptor(new execute.MetaDataNameInterceptor());
api.hooks.execute.addInterceptor(new execute.LogResponseInterceptor());
}
function initProvideEnvironmentsHook(api: models.HttpyacHooksApi) {
Expand Down
16 changes: 0 additions & 16 deletions src/plugins/core/response/handleNameMetaData.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/plugins/core/response/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './handleNameMetaData';
export * from './jsonResponseInterceptor';
export * from './setLastResponseInVariables';

0 comments on commit c7d9f78

Please sign in to comment.