zfcampus / zf-rest

BSD 3-Clause "New" or "Revised" License
32 stars 37 forks source link

zfr-cors is short circuited when resource controllers return ApiProblem objects #17

Closed boxidau closed 10 years ago

boxidau commented 10 years ago

Hi,

I'm having an issue where zfr-cors doesn't seem to be given the chance to add its headers if a resource controller returns an ApiProblem. Causing API requests from browsers to fail with an XMLHttpRequest error rather than allowing the application to handle the API failure gracefully.

boxidau commented 10 years ago

So I've found that in ZF\Rest\RestController->onDispatch if an ApiProblem is returned from a dispatched method then a new ApiProblemResponse is returned and the existing response object is overwritten.

Perhaps some sort of header whitelist needs to be implemented here to copy selected headers from the existing response?

Sorry if this is a stupid suggestion, I haven't been working in Zend for very long at all :( and I'm certain that there will be a better place for this to occur.