v0.10.0
v0.10.0 is here! π
Features
-
π‘οΈ Reject local unhandled requests (83e0126):
Local HTTP interceptors are now capable of rejecting unhandled requests with
action: 'reject'
. This is useful when you want to ensure that unhandled requests cause a request error. For backward compatibility, the default behavior in local interceptors is still to bypass unhandled requests. Learn more. -
π‘ Improved unhandled request API (e53cb89)
To preserve the previous behavior, you can use
action: 'bypass'
for local interceptors andaction: 'reject'
for remote interceptors.Migration guide:
-
If you set an unhandled request strategy for a local interceptor, add
action: 'bypass'
to preserve the previous behavior.const interceptor = httpInterceptor.create<Schema>({ type: 'local', - onUnhandledRequest: { log: false }, + onUnhandledRequest: { action: 'bypass', log: false }, }); const interceptor = httpInterceptor.create<Schema>({ type: 'local', - onUnhandledRequest: { log: true }, + onUnhandledRequest: { action: 'bypass', log: true }, });
-
If you set an unhandled request strategy for a remote interceptor, add
action: 'reject'
to preserve the previous behavior.const interceptor = httpInterceptor.create<Schema>({ type: 'remote', - onUnhandledRequest: { log: false }, + onUnhandledRequest: { action: 'reject', log: false }, }); const interceptor = httpInterceptor.create<Schema>({ type: 'remote', - onUnhandledRequest: { log: true }, + onUnhandledRequest: { action: 'reject', log: true }, });
-
If you used an unhandled request strategy function, the
context
parameter was removed andawait context.log()
can be replaced with areturn
of the desired strategy.const interceptor = httpInterceptor.create<Schema>({ type: 'local' - onUnhandledRequest: async (request, context) => { - const url = new URL(request.url); - - // Ignore only unhandled requests to /assets - if (!url.pathname.startsWith('/assets')) { - await context.log(); - } - }, + onUnhandledRequest: async (request) => { + const url = new URL(request.url); + + // Ignore only unhandled requests to /assets + return { + action: 'bypass', // Use 'reject' for remote interceptors + log: !url.pathname.startsWith('/assets'), + } + }, });
-
If you set a default unhandled request strategy, use
httpInterceptor.default.local.onUnhandledRequest
orhttpInterceptor.default.remote.onUnhandledRequest
.- httpInterceptor.default.onUnhandledRequest({ log: false }); + httpInterceptor.default.local.onUnhandledRequest = { + action: 'bypass', + log: false, + }; + httpInterceptor.default.remote.onUnhandledRequest = { + action: 'reject', + log: false, + };
- httpInterceptor.default.onUnhandledRequest({ log: true }); + httpInterceptor.default.local.onUnhandledRequest = { + action: 'bypass', + log: true, + }; + httpInterceptor.default.remote.onUnhandledRequest = { + action: 'reject', + log: true, + };
-
If you used a default unhandled request strategy function, the
context
parameter was removed andawait context.log()
can be replaced with areturn
of the desired strategy.- httpInterceptor.default.onUnhandledRequest(async (request, context) => { - const url = new URL(request.url); - - if (!url.pathname.startsWith('/assets')) { - await context.log(); - } - }); + httpInterceptor.default.local.onUnhandledRequest = async (request) => { + const url = new URL(request.url); + + return { + action: 'bypass', + log: !url.pathname.startsWith('/assets'), + }; + }; + httpInterceptor.default.remote.onUnhandledRequest = async (request) => { + const url = new URL(request.url); + + return { + action: 'reject', + log: !url.pathname.startsWith('/assets'), + }; + };
-
The parameter
onUnhandledRequest.log
in the programmatic interceptor server API was changed tologUnhandledRequests
to better reflect the CLI flag.const server = interceptorServer.create({ hostname: 'localhost', port: 3000, - onUnhandledRequest: { log: false }, + logUnhandledRequests: false, });
-
Setting
httpInterceptor.default.onUnhandledRequest
no longer affects interceptor servers in the programmatic API. To change the default logging behavior, use the parameterlogUnhandledRequests
ininterceptorServer.create(options)
.
-
-
βοΈ Parsed unhandled requests (39fd1bb)
Unhandled requests are now parsed by default, just like interceptor requests.
request.body
,request.searchParams
, andrequest.pathParams
are now available for unhandled requests. This makes it easier to manipulate them and improves the consistency of the API.
Deprecations
-
π Removed the types deprecated in v0.9
Full list of removed types:
Previous (now removed) Replaced by HttpServiceSchema
HttpSchema
HttpServiceMethodsSchema
HttpMethodsSchema
HttpServiceMethodsSchema
HttpMethodsSchema
HttpServiceMethodSchema
HttpMethodSchema
HttpServiceRequestSchema
HttpRequestSchema
HttpServiceResponseSchemaByStatusCode
HttpResponseSchemaByStatusCode
HttpServiceResponseSchema
HttpResponseSchema
HttpServiceResponseSchemaStatusCode
HttpResponseSchemaStatusCode
HttpServiceSchemaMethod
HttpSchemaMethod
HttpServiceSchemaPath
HttpSchemaPath
LiteralHttpServiceSchemaPath
HttpSchemaPath.Literal
NonLiteralHttpServiceSchemaPath
HttpSchemaPath.NonLiteral
PathParamsSchemaFromPath
InferPathParams
ExtractHttpInterceptorSchema
InferHttpInterceptorSchema
Credits
Huge thanks to @diego-aquino for helping!
Full Changelog: v0.9.5...v0.10.0
- feat(#zimic)!: improve unhandled request API (#467) by @diego-aquino in #469
- chore(root): do not automatically install peer deps by @diego-aquino in #472
- chore(root): migrate to eslint 9 by @diego-aquino in #475
- chore(root): bump the npm group with 12 updates by @dependabot in #476
- feat(#zimic): support rejecing local unhandled requests (#387) by @diego-aquino in #481
- feat(#zimic): parse unhandled requests (#480) by @diego-aquino in #482
- refactor(root): improve eslint config by @diego-aquino in #483
- chore(#zimic): remove deprecated resources (#334) by @diego-aquino in #484
- chore(root): bump the npm group with 14 updates by @dependabot in #486
- docs(wiki, #zimic): v0.10.0 by @diego-aquino in #487
- chore(release): zimic@0.10.0 by @diego-aquino in #488