pedestal

caleb.macdonaldblack 2019-02-15T02:23:23.019200Z

500 errors/exceptions don't seem to add the cors header using ::http/allowed-origins. All other requests do. Is there any way to add this without creating an error interceptor to repeat what the ::http/allowed-origins param does. Or something else wrong here?

2019-02-15T15:23:02.021500Z

@caleb.macdonaldblack while Pedestal provides default error handling, I’d recommend implementing your own error handling interceptor which associates a more informative and, possibly, context-specific response. Adding such an error handling interceptor to your common interceptor collection will create a response which will be returns with the relevant CORS headers.

2019-02-15T15:28:47.021800Z

Here are some more details: Default error handling is considered last resort and is interceptor chain provider specific. The servlet interceptor chain provider provides a catchall but it’s implemented within the internal response processing logic. CORS is implemented as an interceptor and only supports the :enter and :leave keys. On :leave it merges the relevant headers to the response :headers map. There is no :error support because, what should it do in the case of an error? This is an application-specific concern. Explicitly handle your errors and you’ll get the result you are looking for.

2019-02-15T15:30:46.022Z

BTW, when I talked about context-specific error handling, I was referring to the error-dispatch helper provided by Pedestal (https://github.com/pedestal/pedestal/blob/master/interceptor/src/io/pedestal/interceptor/error.clj#L17).

2019-02-15T15:31:31.022300Z

It allows you to provide both general and specific error handling in one place

caleb.macdonaldblack 2019-02-15T15:38:48.024500Z

Thank you for for your response. I left my question up to see if there were any other solutions. I did end up using error-dispatch though which is exactly what I needed

2019-02-15T21:47:56.025800Z

I just added a Unit Testing reference to the http://pedestal.io site (http://pedestal.io/reference/unit-testing). @ariel.silverman you may find it useful.

4👍
2019-02-17T16:48:37.029300Z

@ariel.silverman, :thumbsup:. I’ve done something similar in the past but leveraged a fixture.

asilverman 2019-02-19T16:23:21.058500Z

I also had a fixture implementation but ended up abandoning that approach because I want to dynamically change behavior of the mock datastore based on test specific scenarios and realized that fixtures do not allow for arguments and it just seemed a bit clunky.

asilverman 2019-02-19T16:24:45.058700Z

thank you for your help and for taking the initiative to write a guide on pedestal on testing. 🙂

2019-02-19T16:25:41.059100Z

np!