koltyakov / sp-rest-proxy

🌐 SharePoint API Proxy for local development
MIT License
172 stars 43 forks source link

Incorrect proxying of WebFaultException #63

Closed NZainchkovskiy closed 6 years ago

NZainchkovskiy commented 6 years ago

I have custom WCF REST service, hosted in SharePoint. I'm using sp-rest-proxy to test application wich make a request to SharePoint REST API and this custom service. Everything goes great unless WCR REST service throws an exception. throw new WebFaultException<string>(ex.ToString(), HttpStatusCode.InternalServerError) When this code executes, direct GET request returns string response with exception (ex.ToString()). When I make request through proxy, I got json response with something like that: { "type": "Buffer", "data": [ 34, 83, 121, 115, 116, 101, 109, 46, 65, 114, 103, 117, 109, 101 ]}

It's very inconvenient because I can't test exception handling in developer enviroment with sp-rest-proxy, I need to deploy my application to test that behaviour. If it can be fixed, please do it. Thank you!

koltyakov commented 6 years ago

Hi @NZainchkovskiy,

Any chance to scaffold a sample project with custom REST WCF (which would fail the same way) which I can drop into some environment to quickly reproduce the issue?

I checked on a random WCF from a relatively recent project and it works via proxy well.

image

NZainchkovskiy commented 6 years ago

@koltyakov sure, will create a sample project for it. To make it clear, it works when it's executes without exception. Issue only with WebFaultException. I'll be back with example project.

NZainchkovskiy commented 6 years ago

SpRestProxy.zip Without proxy: image With proxy: image

As you can see, I'm just throwing an exception in code, nothing more:

public IEnumerable<string> GetDomainGroups()
{
throw new WebFaultException<string>("I want to see this message through proxy", HttpStatusCode.InternalServerError);
}
koltyakov commented 6 years ago

Ok, so I'm almost there:

image

Checking some parts and going to publish the beta version soon.

koltyakov commented 6 years ago

Done and published. @NZainchkovskiy, please check if the beta (2.7.5-beta3) fixes your issue? npm i -D sp-rest-proxy@beta.

koltyakov commented 6 years ago

@NZainchkovskiy, any update on your end? Did you manage to check the beta, does it work as expected with your case?

NZainchkovskiy commented 6 years ago

@koltyakov sorry for late reply. I had some issue with npm while updating to beta version, then got distracted by other tasks. Now I got an error when I try to npm run proxy

Error: Cannot find module 'C:\VSCode\sp-tasks\node_modules\sp-rest-proxy\dist\package.json'

I will try to do some troubleshooting and will be back to you with updates.

NZainchkovskiy commented 6 years ago

Still no luck with beta. Same issue. Tried remove and add again. Stable 2.7.4 version runs perfectly, but has issues with WebFaultException (it's not a surprise, just statement to be clear).

koltyakov commented 6 years ago

Strange, as beta works well, passes all tests and WebFaultException case behaves the same while requesting through the proxy as on SP page.

NZainchkovskiy commented 6 years ago

Maybe I said it wrong. I have an error with npm run proxy with beta. So I can't even run proxy with it. So can't check original issue. At the same time with 2.7.4 npm run proxy executes without any errors.

NZainchkovskiy commented 6 years ago

Hi! Any updates? If I can somehow fix beta errors on my side - please give me a clue. Thank you!

koltyakov commented 6 years ago

Hey @NZainchkovskiy,

Sorry, didn't know you were waiting for my response as it seemed to me like a sort of a generic node/npm/network issue. And thank you for showing up and triggering me on some extra tests.

Can you try installing sp-rest-proxy@2.7.5-beta4?

It was probably something wrong with beta3. I really thought that you've been facing the problem during the installation process but not a runtime.

NZainchkovskiy commented 6 years ago

UPDATE: Sorry, forgot everything I wrote below. I got this message when I trying to open localhost:8081: image

I tried beta4, there is no issues with starting proxy, and error message is definitely much better! But there is still different messages via proxy and directly from SharePoint. From SharePoint: "I want to see this message through proxy" From proxy: {"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""} I think I can handle this, there is no complex logic to differentiate these messages and handle it, but I think in ideal world proxy should mimic real service one-to-one. But I know our world not ideal and your tool so great, so it can afford little flaws. :)

NZainchkovskiy commented 6 years ago

In beta3 proxy just not compiled, in beta4 I got runtime error:

Error: ENOENT: no such file or directory, open 'E:\VSCode\sp-item-workflow-history\node_modules\sp-rest-proxy\dist\static\index.html' at Object.openSync (fs.js:443:3) at Object.readFileSync (fs.js:348:35) at GetRouter.serveLocalResources (E:\VSCode\sp-item-workflow-history\node_modules\sp-rest-proxy\dist\core\routers\genericGet.js:86:41) at GetRouter._this.router (E:\VSCode\sp-item-workflow-history\node_modules\sp-rest-proxy\dist\core\routers\genericGet.js:36:23) at Layer.handle [as handle_request] (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\layer.js:95:5) at next (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\layer.js:95:5) at E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\index.js:281:22 at param (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\index.js:354:14) at param (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\index.js:365:14) at Function.process_params (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\index.js:410:3) at next (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\index.js:275:10) at Function.handle (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\index.js:174:3) at router (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\index.js:47:12) at Layer.handle [as handle_request] (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\index.js:317:13) at E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\index.js:284:7 at Function.process_params (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\index.js:335:12) at next (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\index.js:275:10) at E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\index.js:635:15 at next (E:\VSCode\sp-item-workflow-history\node_modules\express\lib\router\index.js:260:14)

koltyakov commented 6 years ago

Hi Nikolay,

I felt that after the refactoring the module should stay in beta for a reason. ;) Thanks for taking the part in testing.

Published beta5.

NZainchkovskiy commented 6 years ago

With beta5 index.html works great, but I still got error {"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""} instead of actual "I want to see this message through proxy". It's better than buffer, but I still can't get actual error, and error coming in different format (json instead of plain text). So I think something goes wrong. :(

koltyakov commented 6 years ago

Well... are you sure that on SP page you see a different response payload, as I don't. The responses are identical. Previously in the comments, I placed response result from fetch. Here is the result using jQuery AJAX:

image

NZainchkovskiy commented 6 years ago

Hey @koltyakov! Sorry, it was my fault. Double checked proxy config and realized I changed SharePoint address to another farm. Now it works perfectly! Many thanks, I think issue can be closed now.

koltyakov commented 6 years ago

Cool! Glad it works for you now. Please use the beta until I'll publish the new version with latest tag after a little while.