Skip to content

Conversation

@jacobsfletch
Copy link
Member

@jacobsfletch jacobsfletch commented Mar 26, 2024

Description

Removes reliance on instanceof when formatting API errors from the REST API. This led to field-level validation errors to not get properly formatted in API responses, i.e. unique fields do not receive their individual validation messages. The reason was because previously, we were checking the error's instanceof in order to properly format the response based on APIError, ValidationError, etc. But changes to TS have made this condition unreliable (see https://dannyguo.medium.com/how-to-fix-instanceof-not-working-for-custom-errors-in-typescript-1df978100a27). Unfortunately the fix described in that article also does not resolve this issue, i.e. setting the prototype in the class' constructor. So instead, we check the name of the constructor explicitly. There might be a better fix for this in the future.

This PR also fixing the casing on the routeError function.

  • I have read and understand the CONTRIBUTING.md document in this repository.

@jacobsfletch jacobsfletch marked this pull request as ready for review March 26, 2024 21:44
@jacobsfletch jacobsfletch changed the title fix(next): removes reliance on instanceoffrom api error formatting fix(next): removes reliance on instanceof from api error formatting Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants