Error Dialog vs. Custom Error

I build a flow: Event Hook Trigger → Run Script

1.) If there is an error I throw the error: throw new Error(“ERROR MESSAGE“);

If I’m an admin, I see the error dialog with the text “ERROR MESSAGE“.
If I’m not the admin, the text is a generic text…!?

Is it possible to display the same error text regardless of authorisation?

2.) Extension “custom error handler”

I tried to resolve this issue using the “custom error handler” extension. I’m using Directus version 11.1.0. Instead of displaying an error dialog, a red error notification appears in the bottom right corner.

How can I display an error dialog instead of the notification?

This error behavior is very strange…

12 Answers

12

Sounds like an issue with the Bulk Import api, would you mind opening an issue in GitHub so the core team can review: https://directus.io/docs/community/reporting-and-support/bug-reporting

Thank you! Appreciate your detailed descriptions and testing.

You can also add a link to this discussion to the issue. :slight_smile:

There's a fix in v11.13.0 (https://github.com/directus/directus/issues/26218). I'll test it. Thanks so much for your support!

Use the Throw Error operation on the false path to customize the error message. eg:

Yes, thank you! For some reason, this scenario doesn't work for me... :(

There are new findings here: The behavior of the Custom Error extension depends on the flow in which it is used. The import flow appears to be a special case where the extension is handled differently (see my comments).

Event Hook Trigger: items.create Manual item creation -> Custom Error appears as message dialog (OK) Import csv -> Custom Error appears as notification "Forbidden" (not OK)

Manual Trigger: No 'normal' Error dialog appears, no Custom Error dialog appears

My test scenario:

Test as admin:

OK!

Test as no-admin:

“ERROR MESSAGE” is not displayed…

Test with custom error handler:

Error output: custom error handler

Ok it took a couple of reads to understand the issue you are facing. Let me ensure I understand:

  • Create Flow with filter(blocking) trigger on item create
  • Create item in Data Studio with plus(+) icon on the collection
    • Custom flow error message shown for both admin & non-admin – correct?
  • Bulk Import items in Data Studio
    • Custom flow error message only shows when admin - non-admin gets generic error Is this correct?​

If it is the second issue, eg the Bulk Import is not returning the custom message, then please open an issue: https://directus.io/docs/community/reporting-and-support/bug-reporting

The error dialog is only displayed if an item is created manually. A red notification is displayed during import.

Sorry for my unclear description, jonathanwagner

Event Hook-Trigger: items.create, filter(blocking)
Test-Szenario 1: Admin, Create Item, throw new Error(“create item”) → [INTERNAL_SERVER_ERROR] item create (OK)
Test-Szenario 2: Admin, Import CSV, throw new Error(“create item”) → [INTERNAL_SERVER_ERROR] item create (OK)
Test-Szenario 3: Admin, Create Item, Custom Error(FORBIDDEN, “Custom Error”, 403) → [FORBIDDEN] Custom Error (OK)
Test-Szenario 4: Admin, Import CSV, Custom Error(FORBIDDEN, “Custom Error”, 403) → Red Notification → Forbidden (Not OK)

Table-Permissions: Create, Read, Update, Delete (All Access)
Test-Szenario 5: No-Admin, Create Item, throw new Error(“create item”) → [INTERNAL_SERVER_ERROR] An unexpected error occurred. (Not OK)
Test-Szenario 6: No-Admin, Import CSV, throw new Error(“create item”) → [INTERNAL_SERVER_ERROR] An unexpected error occurred. (Not OK)
Test-Szenario 7: No-Admin, Create Item, Custom Error(FORBIDDEN, “Custom Error”, 403) → [FORBIDDEN] Custom Error (OK)
Test-Szenario 8: No-Admin, Import CSV, Custom Error(FORBIDDEN, “Custom Error”, 403) → Red Notification → Forbidden (Not OK)

  • Create Flow with filter(blocking) trigger on item create
    → Correct

  • Create item in Data Studio with plus(+) icon on the collection

    • Custom flow error message shown for both admin & non-admin – correct?
      → Correct!
  • Bulk Import items in Data Studio

    • Custom flow error message only shows when admin - non-admin gets generic error Is this correct?​
      → No… Bulk import shows a red notification instead of an error dialog

Tests with Directus v11.13.2

Event Hook-Trigger: items.create, filter(blocking)
Test-Szenario 1: Admin, Create Item, throw new Error(“create item”) → [INTERNAL_SERVER_ERROR] item create (OK)
Test-Szenario 2: Admin, Import CSV, throw new Error(“create item”) → [INTERNAL_SERVER_ERROR] item create (OK)
Test-Szenario 3: Admin, Create Item, Throw Error(INVALID_PAYLOAD, “INVALIDPAYLOAD”, 405) → [INVALID_PAYLOAD] INVALID PAYLOAD (OK)
Test-Szenario 4: Admin, Import CSV, Throw Error(INVALID_PAYLOAD, “INVALIDPAYLOAD”, 405) → [INVALID_PAYLOAD] INVALID PAYLOAD (OK)
Test-Szenario 5: Admin, Create Item, Custom Error(FORBIDDEN, “Custom Error”, 403) → [FORBIDDEN] Custom Error (OK)
Test-Szenario 6: Admin, Import CSV, Custom Error(FORBIDDEN, “Custom Error”, 403) → [FORBIDDEN] Custom Error (OK)

Table-Permissions: Create, Read, Update, Delete (All Access)
Test-Szenario 7: No-Admin, Create Item, throw new Error(“create item”) → [INTERNAL_SERVER_ERROR] An unexpected error occurred. (NOK)
Test-Szenario 8: No-Admin, Import CSV, throw new Error(“create item”) → [INTERNAL_SERVER_ERROR] An unexpected error occurred. (NOK)
Test-Szenario 9: No-Admin, Create Item, Throw Error(INVALID_PAYLOAD, “INVALIDPAYLOAD”, 405) → [INVALID_PAYLOAD] INVALID PAYLOAD (OK)
Test-Szenario10: No-Admin, Import CSV, Throw Error(INVALID_PAYLOAD, “INVALIDPAYLOAD”, 405) → [INVALID_PAYLOAD] INVALID PAYLOAD (OK)
Test-Szenario11: No-Admin, Create Item, Custom Error(FORBIDDEN, “Custom Error”, 403) → [FORBIDDEN] Custom Error (OK)
Test-Szenario12: No-Admin, Import CSV, Custom Error(FORBIDDEN, “Custom Error”, 403) → [FORBIDDEN] Custom Error (OK)

The operations "Throw Error" and "Throw Custom Error" work fine with Directus 11.13.2! "throw new Error" behaves differently as an admin and as a non-admin.

That is expected and designed behavior. The error operation was added for explicit custom messages. Glad it is working as expected on latest release