Custom error display in frontend with web api as backend

Hello!

Im currently using PdfViewer where im trying to return a custom error.

i could not find any documentation on this so ill try post my question here.

Image_5540_1718699415652


Image_9007_1718699382208

Image_8155_1718699568630


i wish to have a customisable error message dissplayed here at the pdf-viewer, but i cant seem to find a solution for it.

How would i proceed to fix this?


3 Replies

CK Chinnamunia Karthik Chinna Thambi Syncfusion Team June 19, 2024 01:19 PM UTC

Hi Oscar,

You can customize the "Invalid PDF file type or PDF file not found. Please select a valid PDF file" error message on the client-side using the `defaultLocale` property. We have provided the code snippet and sample for this functionality.


Code snippet:


 

const created = (args) => {

    viewer.defaultLocale["Import PDF Failed"] = "Error! Retrieving this document has failed"

}

 

<PdfViewerComponent

    ref={(scope) => {

    viewer = scope;

    }}

    id="container"

    documentPath="test.pdf"

    serviceUrl="https://services.syncfusion.com/react/production/api/pdfviewer"

    created= {created}

    style={{ height: '640px' }}

    >

    <Inject

    services={[

        Toolbar,

        Magnification,

        Navigation,

        LinkAnnotation,

        BookmarkView,

        ThumbnailView,

        Print,

        TextSelection,

        TextSearch,

        Annotation,

        FormFields,

        FormDesigner,

        PageOrganizer,

    ]}

    />

</PdfViewerComponent>


Sample: https://stackblitz.com/edit/react-tgz4gc?file=index.js



OA oskar ahling June 26, 2024 12:24 PM UTC

Hello, this solution did not work.
As you see the code above the error handeling is complaining about string string cant be an Ipdfviewer type.

Also we're using typescript. Could you help again with a specific response in regards to the code i provided you?



CK Chinnamunia Karthik Chinna Thambi Syncfusion Team June 27, 2024 02:40 PM UTC

Hi Oskar,

Currently, we don't have support for sending custom errors from server to client. However, you can customize the error message "Invalid PDF file type or PDF file not found. Please select a valid PDF file" on the client-side using the `defaultLocale` property. So, we have provided a sample to demonstrate how to customize the error message on the client-side.


Loader.
Up arrow icon