This is a way to do it. The best? Probably not. First spring typically handles most errors in a generic way that is good enough for almost all clients. Most clients are only going to care about failure or security or success. If not the actual best way to do it is to throw a custom exception and annotate that exception so it will throw the desired HTTP code. That way you have a custom exception which is the right thing to do and then handle them in a specific way versus a somewhat less generic way via the controller advice
I agree for internal facing applications. For external you don't want the stacktrace to be sent to the client since it allows would be hackers to gain insight into the inner workings of your application.
See that's the thing about springboat there's always a way to handle that via configuration. There is a one line configuration to turn that off and you can do it by environment with profiles
Yeah I understand what you're saying but I've got about 40 spring boot applications and I've never needed it. The default spring boot mechanism handles the majority of unexpected events.
Well it's not really work style it's really about if you're using spring boot techniques or Reinventing the wheel. But I mean if that's what you want to do go for it LOL
This is a way to do it. The best? Probably not. First spring typically handles most errors in a generic way that is good enough for almost all clients. Most clients are only going to care about failure or security or success. If not the actual best way to do it is to throw a custom exception and annotate that exception so it will throw the desired HTTP code. That way you have a custom exception which is the right thing to do and then handle them in a specific way versus a somewhat less generic way via the controller advice
I agree for internal facing applications. For external you don't want the stacktrace to be sent to the client since it allows would be hackers to gain insight into the inner workings of your application.
See that's the thing about springboat there's always a way to handle that via configuration. There is a one line configuration to turn that off and you can do it by environment with profiles
Thanks for the feedback :) yeah you are right, however I've found that controller advice can also be like a final fishnet for any unexpected events.
Yeah I understand what you're saying but I've got about 40 spring boot applications and I've never needed it. The default spring boot mechanism handles the majority of unexpected events.
I have used it :D so it really depends on your work style
Well it's not really work style it's really about if you're using spring boot techniques or Reinventing the wheel. But I mean if that's what you want to do go for it LOL
Setting HTTP code for you own exceptions - is the best way to high coupled monolith with mixed everything together. "The best? Probably not." )