MastodonClient: fix HTTP 204 responses
This commit is contained in:
parent
b07bcd3ead
commit
07c98a21e0
|
@ -90,6 +90,12 @@ export class MastodonClient {
|
||||||
throw new HTTPError(response, request);
|
throw new HTTPError(response, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix for non-compliant browsers.
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/Response/body
|
||||||
|
if (response.status === 204 || request.method === 'HEAD') {
|
||||||
|
return new MastodonResponse(null, response);
|
||||||
|
}
|
||||||
|
|
||||||
return new MastodonResponse(response.body, response);
|
return new MastodonResponse(response.body, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { AxiosError } from 'axios';
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { defineMessages, useIntl } from 'react-intl';
|
import { defineMessages, useIntl } from 'react-intl';
|
||||||
|
|
||||||
import { closeModal } from 'soapbox/actions/modals.ts';
|
import { closeModal } from 'soapbox/actions/modals.ts';
|
||||||
|
import { HTTPError } from 'soapbox/api/HTTPError.ts';
|
||||||
import { useApi } from 'soapbox/hooks/useApi.ts';
|
import { useApi } from 'soapbox/hooks/useApi.ts';
|
||||||
import { useAppDispatch } from 'soapbox/hooks/useAppDispatch.ts';
|
import { useAppDispatch } from 'soapbox/hooks/useAppDispatch.ts';
|
||||||
import { useInstance } from 'soapbox/hooks/useInstance.ts';
|
import { useInstance } from 'soapbox/hooks/useInstance.ts';
|
||||||
|
@ -43,7 +43,7 @@ const useCaptcha = () => {
|
||||||
setYPosition(topI);
|
setYPosition(topI);
|
||||||
setXPosition(leftI);
|
setXPosition(leftI);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('Error loading captcha:');
|
toast.error('Error loading captcha');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -72,11 +72,10 @@ const useCaptcha = () => {
|
||||||
dispatch(closeModal('CAPTCHA'));
|
dispatch(closeModal('CAPTCHA'));
|
||||||
toast.success(messages.sucessMessage);
|
toast.success(messages.sucessMessage);
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
setTryAgain(true);
|
setTryAgain(true);
|
||||||
const error = e as AxiosError;
|
|
||||||
const status = error.request?.status;
|
|
||||||
|
|
||||||
|
const status = error instanceof HTTPError ? error.response.status : undefined;
|
||||||
let message;
|
let message;
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
|
@ -88,8 +87,10 @@ const useCaptcha = () => {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
message = intl.formatMessage(messages.errorMessage);
|
message = intl.formatMessage(messages.errorMessage);
|
||||||
|
console.error(error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
toast.error(message);
|
toast.error(message);
|
||||||
}
|
}
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
|
|
Loading…
Reference in New Issue