:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

The `ErrorReportingService` is an SPI to customise the actions taken by the framework if an unexpected exception is raised.



Hit the 'Trigger An Error' button an see what happens!

The framework does provide a default error handling implementation.
However, by implementing a custom `ErrorReportingService` you may
provide a more user-friendly experience:

[source,java]
----
import org.springframework.stereotype.Service;

@Service
public class DemoErrorReportingService implements ErrorReportingService {

    @Override
    public Ticket reportError(ErrorDetails errorDetails) {

        String reference = "#0";
        String userMessage = errorDetails.getMainMessage();
        String details = "Apologies!";

        val mailTo = MailTo.builder()
        .receiver("support@hello.world")
        .subject("[Simple-Module] Unexpected Error ("+reference+")")
        .body(MailTo.mailBodyOf(errorDetails))
        .build();

        StackTracePolicy policy = StackTracePolicy.SHOW;
        val ticket = new EmailTicket(mailTo, reference, userMessage, details,
               policy,
               "http://www.randomkittengenerator.com/cats/rotator.php");

        return ticket;
    }


}
----

See the ErrorReportingService implemented for this demo here:
link:${SOURCES_DEMO}/demoapp/dom/error/service[sources].
