-
Notifications
You must be signed in to change notification settings - Fork 140
Global error handling use MST #339
Comments
Very interested in this topic as well. Maybe we could start by sharing our way to do it or our ideas? That would open up the discussion. |
Hi! I don't have a repo example, but this is the rough code for what I've done for this in another project, in ignite-bowser's file structure:
in
The setup works like this:
That way, the app wrapper is observing the I'm sure someone who's more MST-savvy can make this even cleaner somehow! Example repo incoming 👀 Edit: example repo at https://github.com/jksaunders/ignite-bowser-339 ^ In this repo, the mobile app has a valid API request button (no errors shown) and an invalid API request button (error message briefly shown). It's all from a single handler, observable anywhere! |
for your ex, catch the token expires, please check api-problem.ts, and here how can i handle the token expires: return null |
Thank you so much! It really helped |
thanks for sharing \o/, another suggestion here instead of changing the logic to use import * as SecureStorage from "@utils/secure-storage"
import { Api } from "../services/api"
import { ACCESS_TOKEN_KEY } from "@utils/constants"
/**
* The environment is a place where services and shared dependencies between
* models live. They are made available to every model via dependency injection.
*/
export class Environment {
constructor() {
this.api = new Api()
}
async setup() {
await this.api.setup()
this.api.apisauce.addMonitor((response) => {
if (this.setResponse) {
this.setResponse(response)
}
})
}
/**
* Our api.
*/
api: Api
setResponse: (response: any) => void
} |
Hello everyone!
I’ve been looking for a solution for a very long time, I can’t find it anywhere.
How to make a global error handler from the api server response to show the user a modal window use MST or something else? Or for example, if the token has expired redirect to the authorization window, if the answer 500 came to show the Houston we have problems screen. depending on server response.
a single handler that will consider different cases and show info windows
🙏🏻
The text was updated successfully, but these errors were encountered: