czottmann / obsidian-actions-uri

A plugin for Obsidian (https://obsidian.md) that adds additional `x-callback-url` endpoints to the app for common actions — it's a clean, super-charged addition to Obsidian URI.
https://zottmann.dev/obsidian-actions-uri/
MIT License
138 stars 6 forks source link

[ZCO-135] Fix zod validation errors not sending out `x-error` callbacks #72

Closed czottmann closed 1 year ago

czottmann commented 1 year ago

When a new URL request comes in, the request parameters are validated via zod schemas. If they "fit" a schema, the relevant route handler is called. Otherwise, only an error toast is displayed in Obsidian, and since we're dealing with a malformed request, the x-error callback won't be triggered. This is by design: bad request, tough luck.

With the introduction of zodExistingFilePath and zodExistingFolderPath this starts to become a problem, however, because now the request validation of some routes hinges on (for example) the file parameter referencing an existing file. If the referenced file is 404, the validation fails.

I'd like to keep the file reference validation, so I'll need to find a way to send out x-error callbacks even for malformed requests.

Idea: if the malformed request contains and x-error parameter, honor it instead of just backing off right away.

ZCO-135