Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/improve lettera error messages #1486

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

jllang
Copy link
Contributor

@jllang jllang commented Sep 13, 2023

No description provided.

@github-actions
Copy link

Deploy previews are ready 😎

packages/components/src/Lettera.purs Outdated Show resolved Hide resolved
packages/components/src/Lettera.purs Outdated Show resolved Hide resolved
packages/components/src/Lettera.purs Outdated Show resolved Hide resolved
packages/components/src/Lettera.purs Outdated Show resolved Hide resolved
@jllang jllang requested a review from kaol September 18, 2023 10:48
@github-actions
Copy link

Deploy previews are ready 😎

@jllang jllang marked this pull request as ready for review September 18, 2023 11:03
@@ -633,3 +639,105 @@ editorialIdToUuid editorialId =
url_namespace :: UUID.UUID
url_namespace = unsafePartial $ fromJust $ UUID.parseUUID "6ba7b811-9dad-11d1-80b4-00c04fd430c8"

encodeRequestHeaders :: Array AX.RequestHeader -> Maybe Json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Lettera.Models is too busy already and nothing in here uses these so it's not justified by dependencies either. The focus of this module is diluted if it gets Affjax imports to it. If you're moving these from Lettera make it a new module. Lettera.Requests or if you have a better idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New module sounds like a great idea!


data LetteraError
= ResponseError
{ letteraErrorRequest :: Json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I said it already but don't use Json on this level. Leave generating it to the encodeJson instance. Ditto for HttpError. If we need users of this code to do actions based on responses then that's a lot more convenient format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but then we'll have more polymorphic type variables to deal with.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started to think that maybe including requests and responses in the error type is not the best solution to start with. That information is needed for logging but is it really an essential part of an error value? Perhaps we could consider moving the logging from Mosaico to Affresco to the place where we have the best information about the requests, responses and/or other context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that If I generalise the Json type occurrences into type variables, then Mosaico and Affresco disagree whether the getFrontpage and getFrontpageHtml are dealing with LetteraResponse String String a or LetteraResponse Json Json a.

encodeRequestHeaders [] = Nothing
encodeRequestHeaders hs =
let encodeHeader h obj = flip extend obj $ case h of
AX.Accept (MediaType v) -> "Accept" := v
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're doing white spaces for alignment use it on := too.

AX.Accept (MediaType v) -> "Accept" := v
AX.ContentType (MediaType v) -> "ContentType" := v
AX.RequestHeader k v -> k := v
in Just $ foldr encodeHeader jsonEmptyObject hs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to include authorization headers in it? I think a better default would be to scrub them from LetteraResponse (and if convenient make it easy in the source to enable them for dev use when needed).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I'll have a look at this tomorrow.

@github-actions
Copy link

Deploy previews are ready 😎

@github-actions
Copy link

Deploy previews are ready 😎

@github-actions
Copy link

Deploy previews are ready 😎

@github-actions
Copy link

Deploy previews are ready 😎

@github-actions
Copy link

Deploy previews are ready 😎

@github-actions
Copy link

Deploy previews are ready 😎

@jllang jllang force-pushed the feature/improve-lettera-error-messages branch from ef4c146 to 74ec015 Compare October 5, 2023 05:58
@github-actions
Copy link

github-actions bot commented Oct 5, 2023

Deploy previews are ready 😎

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.

2 participants