Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors thrown in interceptors are consumed by the Bridge #12

Open
Prinsn opened this issue Jul 26, 2019 · 2 comments
Open

Errors thrown in interceptors are consumed by the Bridge #12

Prinsn opened this issue Jul 26, 2019 · 2 comments

Comments

@Prinsn
Copy link

Prinsn commented Jul 26, 2019

I'm not sure which side of things this is (currently fighting with karma and karma plugins that claim to provide better stack trace info) but I'm currently getting unit test failures of the pattern

Error: undefined: undefined
    at createError (http://localhost:9876/_karma_webpack_/webpack:/node_modules/breeze-client/breeze.debug.js:16247:1)
    at handleHttpError (http://localhost:9876/_karma_webpack_/webpack:/node_modules/breeze-client/breeze.debug.js:16237:1)
    at Object.error (http://localhost:9876/_karma_webpack_/webpack:/node_modules/breeze-client/breeze.debug.js:16074:1)
    at SafeSubscriber.errorFn [as _error] (http://localhost:9876/_karma_webpack_/webpack:/node_modules/breeze-bridge2-angular/index.js:172:1)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/Subscriber.js:192:1)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.error (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/Subscriber.js:143:1)
    at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/Subscriber.js:79:1)
    at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/Subscriber.js:59:1)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/Subscriber.js:79:1)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/internal/Subscriber.js:59:1) thrown

Was conflicted about which breeze project this went with, but the highest reference to breeze in this case is the bridge itself, and I'm still trying to figure out what's going on.

reference in question

  at SafeSubscriber.errorFn [as _error] (http://localhost:9876/_karma_webpack_/webpack:/node_modules/breeze-bridge2-angular/index.js:172:1)

I don't know if this is a problem with internal error logging, but I'm currently stumped as to figure out what is actually failing, as LOG: 'breeze error', Error: undefined: undefined is pretty opaque

@Prinsn
Copy link
Author

Prinsn commented Jul 26, 2019

Actually, think I just figured out what it was doing.

I'm using an interceptor to mock the backend and was using a throw to notify the test that there was an unmapped endpoint in the interceptor, so that the test would fail with the information in question.

in errorFn() the httpResponse object is

{config: HttpRequest, data: "undefined: undefined", getHeaders: ƒ, status: undefined, ngConfig: HttpRequest, …}
config: HttpRequest {url: "http://localhost:9876/breeze/getTaxableIncomeForPeriod?periodId=0", body: null, reportProgress: false, withCredentials: false, responseType: "text", …}
data: "undefined: undefined"
getHeaders: ƒ getHeaders(headerName)
ngConfig: HttpRequest {url: "http://localhost:9876/breeze/getTaxableIncomeForPeriod?periodId=0", body: null, reportProgress: false, withCredentials: false, responseType: "text", …}
response: "http://localhost:9876/breeze/getTaxableIncomeForPeriod?periodId=0 is not mapped in the interceptor"
status: undefined
statusText: undefined
__proto__: Object

The response being the thrown error, and the "data" being what's returned to the unit test runner.

This both obfuscates the error, and will sometimes allow the test to pass (haven't quite figured out why on part 2).

This could very well be the intended and expected use case of HttpInterceptors, as I'm pretty green to Angular2.

@Prinsn Prinsn changed the title Stack Trace Debugging in Unit Tests Errors thrown in interceptors are consumed by the Bridge Jul 26, 2019
@Prinsn
Copy link
Author

Prinsn commented Jul 26, 2019

The mock is working, so it's apparently not that hard to fix once you dig down far enough.

For anyone that has ended up here:

var url = req.url.toLowerCase();
if (unmappedEndpoints.find(e => url.includes(e.toLowerCase())))
        {
            //As these are queryables, an empty array is a valid response
            return of(new HttpResponse({ body: "[]", status: 200 }));
        }

and just populate an array of all the endpoints you've yet to handle for

var unmappedEndpoints = [ 
           ...
            "breeze/getpartnerbyid"
           ...
        ];

All normal defensive coding practices around handling breeze responses was sufficient and nothing other than the above had to be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant