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

Observe API service #119

Merged
merged 25 commits into from
Nov 14, 2019
Merged

Observe API service #119

merged 25 commits into from
Nov 14, 2019

Conversation

batpad
Copy link
Member

@batpad batpad commented Oct 30, 2019

Service that actions can call to talk to the Observe API.

Currently, implements a base callAPI function that other API methods can call - handles setting the authorization header and passing parameters for GET and POST requests.

Sets up a simple test to call the getProfile action that currently just console.logs the user profile information fetched from the API.

Next steps:

  • Wire this up to the action to submit traces, and sketch out what the actions, reducers and error handling looks like.

cc @vgeorge @geohacker

@vgeorge
Copy link
Member

vgeorge commented Oct 30, 2019

@batpad, developmentseed/observe-dashboard#16 has a working implementation of async actions based the framework conceived by Daniel. It also includes a wrapper function to make authenticated requests seamlessly and a basic example on how to read data and handle errors.

@batpad batpad force-pushed the feature/observe-api-service branch from 9310ec5 to 4977533 Compare November 4, 2019 09:27
@batpad
Copy link
Member Author

batpad commented Nov 5, 2019

Have wired up the POST to post new traces to the API. It currently stores errors in an errors array in the trace object in the state. We can probably refine the error types and messages when dealing with displaying traces on the list page.

I'll add some tests for different status responses from the API. Let me know if there are thoughts / questions on the code so far, @geohacker @vgeorge @sethvincent .

TODO:

  • Tests for error responses from the API
  • Clean up extraneous console.logs

@sethvincent
Copy link
Contributor

@batpad I pushed a commit with some small changes needed to get things running.

I can login fine. It seems like I'm getting errors sending photos to the api:

response data {"error": "Bad Request", "message": "Invalid request payload input", "statusCode": 400} 400

Not sure yet if this is an api problem or an app problem. I can follow up with more debugging tomorrow.

@batpad
Copy link
Member Author

batpad commented Nov 8, 2019

@sethvincent oops sorry I wasn't more clear -- this PR only includes the actions to POST Traces. If the structure looks okay and that works, I thought I'd work on photos in a separate PR.

@batpad
Copy link
Member Author

batpad commented Nov 8, 2019

@sethvincent thanks for the catch on persisting the token.

@sethvincent
Copy link
Contributor

@batpad oh ok that makes sense. I'll take another quick look. I feel like what's here is pretty great.

@sethvincent
Copy link
Contributor

I'm getting an error when posting to observe-api:

LOG  response data {"error": "Bad Request", "message": "Invalid request payload input", "statusCode": 400} 400
LOG  error [TypeError: undefined is not an object (evaluating 'data.properties.id')]

I think because properties.id isn't defined in the validation for the traces POST endpoint? I'm not really sure that makes sense though. I don't see an error logged on the api output. @vgeorge @batpad

traces[index].pending = false
traces[index].uploading = false
traces[index].id = action.newId
if (!traces[index].properties) {
Copy link
Contributor

Choose a reason for hiding this comment

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

My original idea was not correct. The error I was seeing was because the properties object doesn't exist sometimes when adding the id.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm it seems a bit strange that the properties object would not exist - this maybe better to ensure a bit further up when the trace is being created. Let me look a bit closer. Thanks for the catch / fix.

@sethvincent
Copy link
Contributor

I resolved the above error and it seems now that if a trace description is an empty string that i get an Invalid request payload input error. I'm not sure the empty string is the problem, but it definitely works so far when I include a description. This seems like it may be more on the API side.

A higher-level issue I've noticed is that if the server restarts after making changes the next time I try to post a trace the app will crash and stay in that state until i delete it and reinstall. Presumably something similar would happen anytime the access token would expire? We may need to make an issue for this and tackle it in a follow-up pr if not in this one.

@batpad
Copy link
Member Author

batpad commented Nov 11, 2019

I resolved the above error and it seems now that if a trace description is an empty string that i get an Invalid request payload input error. I'm not sure the empty string is the problem, but it definitely works so far when I include a description. This seems like it may be more on the API side.

This looks fixed by developmentseed/observe-api#32

A higher-level issue I've noticed is that if the server restarts after making changes the next time I try to post a trace the app will crash and stay in that state until i delete it and reinstall. Presumably something similar would happen anytime the access token would expire? We may need to make an issue for this and tackle it in a follow-up pr if not in this one.

I have made an issue for this here: #132

I'm a bit conflicted on whether to tackle this in this PR or as the next follow-up. I can't quite wrap my head around the cleanest way to handle token expiry, and also think it may need some UI pieces figured out.

I'm going to hold off on merging this just yet though, because this is a pretty bad issue, and we should think this through.

Thanks a lot for the fixes and review, @sethvincent .

@batpad
Copy link
Member Author

batpad commented Nov 13, 2019

I added tests for the reducer, and also changed to using a single status variable to hold the pending, uploading, or uploaded status of the feature, similar to edits.

@geohacker - if this looks good, I think we can merge. And then I can start working on the API token expiry in a separate PR.

@batpad batpad changed the title [wip] Observe API service Observe API service Nov 14, 2019
Copy link
Member

@geohacker geohacker left a comment

Choose a reason for hiding this comment

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

I tested this on iOS and seemed to work well. I think we should test again after building the Your Traces screen. I got a promise rejection warning when I tried to 'Get Observe API profile' in the settings -- might be something minor but just noting.

@batpad batpad merged commit 0122d54 into develop Nov 14, 2019
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.

4 participants