Not able to figure out Typescript Syntax for using AxiosResponse

I was working on a bug in project ocl-client in typescript

I came across Promise<AxiosResponse> image

  versions: {
    retrieve: (dictionaryUrl: string): Promise<AxiosResponse<any>> =>
      authenticatedInstance.get(`${dictionaryUrl}versions/?verbose=true`),
    create: (
      dictionaryUrl: string,
      data: DictionaryVersion
    ): Promise<AxiosResponse<APIDictionaryVersion>> =>
      authenticatedInstance.post(`${dictionaryUrl}versions/`, data),
    update: (
      dictionaryUrl: string,
      data: DictionaryVersion
    ): Promise<AxiosResponse<APIDictionaryVersion>> =>
        authenticatedInstance.put(`${dictionaryUrl}${data.id}/`, data)
  },

I want to an alert or console.log the error in Axios call

I am not able to figure out where do I add error.also I am not able to find this syntax(typescript) on net.

Any tutorial link will be very helpfull or solution

Axios errors should already be being logged to the console without you needing to do anything. This is because almost all API calls are wrapped in createActionThunk() which runs the AxiosRequest and logs errors that occur.

1 Like

@ibacher thanks for your reply but if I want to show a alert on particular error (basically ER0RR 409)

I want to believe you are fixing a validation issue but before you think of an error to be displayed ensure at some point or another the page wasn’t displaying the error when it happened. To achieve this , type console.log() in your code base (in the .tst page where you are supposed to make the changes) then save. This command helps to print the information of a given page but it is not part of the changes to be committed. Then go to the page where the changes are to be made on your server -> Right click ->inspect -> console to confirm the error thrown. After confirming if the error exists or not that is when you take the next step of how to display the missing error. I pray I don’t confuse you more.

@jwnasambu yes I got that ,but how I am suppose to get that error from this this axios call (say put call)

    update: (
      dictionaryUrl: string,
      data: DictionaryVersion
    ): Promise<AxiosResponse<APIDictionaryVersion>> =>
        authenticatedInstance.put(`${dictionaryUrl}${data.id}/`, data)

if put call through an error how can I catch that error (the syntax to do that) ?

Which ticket are you working on?

This is the path to the page you are supposed to make the changes on src>app>dictionaries>components>DictionaryVersionForm.tsx look at the error in the prop

@jwnasambu oh! sorry I didn’t see that so, I was thinking of catch the error on axios request and give the alert.

@nkumar If you need to add an error message for a particular status code that doesn’t have a message from the backend, you may want to take a look at the STATUS_CODES_TO_MESSAGES construct.

2 Likes