Fork me on GitHub
#pathom
<
2018-10-28
>
currentoor00:10:57

@wilkerlucio yes the key is there

wilkerlucio00:10:15

@currentoor then you must check on the fulcro side of things, if the remote is getting the data the job is done in pathom side

wilkerlucio00:10:02

I see your key on the map is another map, is that expected?

wilkerlucio00:10:13

feels like it should have just the id there (not a map with id in it)

currentoor00:10:56

yeah that’s the weird part

currentoor00:10:10

seems like it looses it’s tempid encoding

currentoor00:10:40

i believe tempids under the hood are encoded like that

wilkerlucio00:10:05

you should check your transit configuration, you need to support tempids there

wilkerlucio00:10:17

the fulcro default one usually works, but you also have to check your server side

currentoor00:10:41

yeah weird stuff, well thanks for the help

currentoor00:10:54

at least we know pathom is doing what its supposed to simple_smile

currentoor00:10:59

but one thing to note is this was working before we moved the parser to pathom

wilkerlucio00:10:59

you just changed the parser? you can try checking the types in an out before encoding, might tell something

wilkerlucio00:10:15

I gotta go now, but let me know if you figure more out

currentoor20:10:03

is there a way to make exception bubble up to the client?

currentoor20:10:22

i was relying on mutations throwing exceptions when something goes wrong

currentoor20:10:57

for example i do authorization check and throw an exception if permissions are not valid

wilkerlucio20:10:23

@currentoor the error plugin is there to prevent that, you can use the flag ::p/fail-fast? true to force it bubble, but I suggest you also consider another approach, what I usually do is return a map with some special key like ::p/errors that tells me that request failed

wilkerlucio20:10:33

this way I can handle it on the client like any other data

wilkerlucio20:10:21

but if you really want to keep mutations blowing, you can just modify the error-handler-plugin, if you look at its definition this is what you will find:

wilkerlucio20:10:22

(def error-handler-plugin
  {::wrap-read   wrap-handle-exception
   ::wrap-parser wrap-parser-exception
   ::wrap-mutate wrap-mutate-handle-exception})

wilkerlucio20:10:51

so you can dissoc the ::wrap-mutate to remove the error catcher from mutations only

wilkerlucio20:10:12

like: ::p/plugins [(dissoc p/error-handler-plugin ::p/wrap-mutate)]

currentoor20:10:46

thanks @wilkerlucio, i’ll try the other approach you recommend

currentoor20:10:44

So using the default error handler plugin, now i’m getting the response back as {:com.wsscode.pathom.core/reader-error "class clojure.lang.ExceptionInfo: Unauthorized Request..."}

currentoor20:10:12

which is nicer, but how do I change the key that the error is on?

currentoor20:10:59

i know there is ::p/process-error but that seems like it’s only for changing the value of the error, not the key

currentoor20:10:35

oh wait never mind, it actually let’s you specify the whole map

currentoor20:10:37

that might work

wilkerlucio20:10:22

yeha, process-error is the way to go to give a custom handling 😉

currentoor21:10:23

so one other thing i want is to change the status of the response to show an error

currentoor21:10:49

that happens one level up from where process-error is being called

currentoor21:10:32

any parser magic to do that?

currentoor21:10:15

because if i put :status 401 in the result of process-error it puts it in the body of the response

wilkerlucio21:10:27

yeah, that's by design to separate the error data from the response data, there is no way to change the up map, but in your UI you can instead render the ::p/reader-error map as the error data

wilkerlucio21:10:20

or there is something that makes this pulling a problem in your scenario?

currentoor21:10:45

well fulcro-websockets has a global-error-callback

currentoor21:10:24

i was using that to log errors and redirect to login (if the status was a 401) or show some other error message

currentoor21:10:25

the UI render ::p/reader-error works only for errors related to what is being rendered

currentoor21:10:03

but if an auth token is expired i’d like to show a top level error then redirect to re-login

currentoor21:10:19

unless i’m mistaken about something

wilkerlucio21:10:44

are you using the pessimist mutations from fulcro incubator?

currentoor21:10:53

in some places yes

currentoor21:10:59

but not for everything

wilkerlucio21:10:24

because thats a good case for it, since it provides the error-action you can use that to handle any redirect concerns

currentoor21:10:02

yes it works for that, but i don’t always want to use pmutate!

currentoor21:10:17

for one it can only do one mutation not a sequence

wilkerlucio21:10:35

I'm looking at the error handler code, I might be able to make it return the full error map, this would make it more extensible, I'm thinking that it actually doesn't even work to the fulcro incubator case now

wilkerlucio21:10:44

because it always use the pathom reader error key

wilkerlucio21:10:26

we can do sending some env flag like ::p/wrap-error? false so you get the full map control without breaking the previous behavior

wilkerlucio21:10:25

@currentoor you think that works?

currentoor21:10:21

what if we had a different key instead? env flag like that seems finicky

currentoor21:10:47

::p/process-error-response for when you want to augment the whole response?

currentoor21:10:55

rather that just the error

wilkerlucio21:10:15

I like the idea, not the name, maybe ::p/process-error2, I still feel like the whole response should be the one to start with

wilkerlucio21:10:59

maybe ::p/process-error*

currentoor21:10:16

What do you mean “the whole response should be the one to start with”?

wilkerlucio21:10:31

I mean to return the whole map instead of a nested key

currentoor21:10:10

What about::p/process-response-error

currentoor21:10:36

That seems like a more descriptive name

currentoor21:10:09

Oh sorry I mean process-response-on-error

wilkerlucio21:10:02

that can work, can you open an issue please?

wilkerlucio21:10:46

I'm double checking now, I think if you do the process error you get the whole map control don't you?

wilkerlucio21:10:52

so you mean in the case you want that error in the response root?

currentoor21:10:38

it looks like i can add a mutate-wrapper that does that right?

wilkerlucio21:10:44

that's kind a leaky abstraction, what if you send 2 mutations and each get a different error status?

currentoor21:10:02

why would each get a different error status?

wilkerlucio21:10:11

2 different requests

wilkerlucio21:10:32

so seems like what you want is some more in the area of a global flags for general errors, is that correct?

currentoor21:10:03

i’m not sure i understand what you mean

currentoor21:10:24

i just want errors to have a non 200 status

currentoor21:10:38

preferably i can set the status depending on the error

wilkerlucio21:10:36

I'm trying to understand that you want to do global app handling of those errors instead of localized handling

wilkerlucio21:10:52

do you have some function in your control that wraps the http calls your api makes?

currentoor21:10:03

basically i’m looking for error behavior of the base fulcro mutation parser, but now i’m starting to think that goes agains the design philosophy of pathom

currentoor21:10:40

like ring middleware? yes, but most of my mutations happen over websockets

wilkerlucio21:10:26

well, it's all doable, it's make to be flexible, but I like to discourage because in principle the API tries to encourage a path with good fault tolerance, in the moment you make some information about a particular error leaks to the global response context, this kind hurts the principle, but at same time I always try to make it as flexible as possible, so I make it hard but still make it possible, so you can do it at your own risk 😉

wilkerlucio21:10:40

so, I was thinking you can write a simple plugin that wraps the parser and injects the http status in case something happens, you can control this state using an atom, here is an example:

currentoor21:10:12

is there a way to wrap the response, like ring middleware?

wilkerlucio21:10:30

(def http-global-status-plugin
  {::p/wrap-parser
   (fn [parser]
     (fn [env tx]
       (let [status-atom (atom nil)
             result (parser (assoc env ::http-status status-atom) tx)]
         (cond-> result
           @status-atom (assoc :http-status @status-atom)))))})

wilkerlucio21:10:44

yeah, wrap-parser wraps the whole thing

wilkerlucio21:10:31

so in this case, you can then add some try-catch in a middlewere of your websocket call, and if it fails it can update this atom from the env so the status will be injected in the root

currentoor21:10:23

i see, so is it a bad idea if i just used p/post-process-parser-plugin to change the out going response on error

currentoor21:10:48

as a last plugin

currentoor21:10:15

right now it gets as input

#:ucv.ui.mobile-pos.screens.camera{new-wash-&-unconfirmed-vehicle
                                   {:error "Unauthorized Request",
                                    :fulcro.incubator.pessimistic-mutations/mutation-errors
                                    "Unauthorized Request",
                                    :status 401,
                                    :body
                                    {:message
                                     "mutation ucv.ui.mobile-pos.screens.camera/new-wash-&-unconfirmed-vehicle unauthorized, s.policy/fail violated"}}}

wilkerlucio21:10:12

you could also write this as a plugin on the client side

wilkerlucio21:10:41

you could wrap the network (pathom has helpers to make that easy) and just look at the mutations in the response (look for symbols at the response root)

wilkerlucio21:10:10

and then you could pull the status from then, and at this point you have all the information (all the statuses) so you could take a decision to pick one in case of ambiguity

currentoor21:10:57

yeah that could work too

wilkerlucio21:10:00

you'r welcome