-
-
Notifications
You must be signed in to change notification settings - Fork 797
Closed
Description
Steps to reproduce
- Create a Feathers app with a single service with a before hook that throws an error.
- Create a second Feathers app with a before hook that sets a variable on
context.paramsand an error hook that prints that param to the console. - Add a service to the second Feathers app that calls the service from the first Feathers app.
- Finally call that service.
Reduced test case
See gist: https://gist.github.com/MitMaro/7c9340d20606d3687ea09dfd498f27cd
'use strict';
const feathers = require('@feathersjs/feathers');
const api1 = feathers();
let api1Params;
let api2Params;
api1.hooks({
async before(context) {
api1Params = context.params;
throw new Error('Error in api1 before hook');
},
});
api1.use('/service1', {
find: () => 'service1 success'
});
const api2 = feathers();
api2.hooks({
before(context) {
api2Params = context.params;
context.params.foo = 'bar'
},
error(context) {
console.log('api2 error hook');
console.log('params from api1 service is the same as context params (should be false)? ', api1Params === context.params);
console.log('params from api2 service is the same as context params (should be true)? ', api2Params === context.params);
console.log('path (should equal /service2):', context.path);
console.log('params.foo (should equal bar):', context.params.foo);
},
});
api2.use('/service2', {
async find(params) {
console.log('service2 call params.foo (should equal bar):', params.foo);
// this will throw an error from the api1 before hook
await api1.service('/service1').find({});
return 'service2 success';
},
});
api2.service('/service2').find().then(console.log).catch(e => console.log(e.message));Output
service2 call params.foo (should equal bar): bar
api2 error hook
params from api1 service is the same as context params (should be false)? true
params from api2 service is the same as context params (should be true)? false
path (should equal /service2): service1
params.foo (should equal bar): undefined
Error in api1 before hook
Actual use case
We have a set of common "internal" services that are not exposed via REST, but are consumed by a second set of services that are available via REST. The internal services have before hooks that handle data validation, that rejects when the data validation fails.
Expected behavior
I would expect that on an error being thrown from another Feathers app instance hook, that the error hook of the calling Feathers app should contain the context of the original call.
Actual behavior
The context in the second Feathers app instead reference the first Feathers app service context.
System configuration
Module versions:
$ npm list @feathersjs/feathers
feathers-subapp-context-error@1.0.0 /home/timoram/code/broken-project-test-cases/feathers-hook-context-removed
└── @feathersjs/feathers@3.1.3
NodeJS version:
$ node --version
v8.10.0
$ npm --version
5.6.0
Operating System:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Pop!_OS 17.10 (Artful Aardvark)
Release: 17.10
Codename: artful
Browser Version:
N/A
React Native Version:
N/A
Module Loader:
N/A
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels