Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
fix: handle 303 status code
Browse files Browse the repository at this point in the history
  • Loading branch information
victorggonzalez committed Apr 12, 2022
1 parent bcd10da commit c75b108
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/api/authentication.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { API_HOST } from '../config/constants';
import { DEFAULT_GET, DEFAULT_POST, checkRequest } from './utils';
import {
DEFAULT_GET,
DEFAULT_POST,
checkRequest,
checkSeeOther,
} from './utils';

// payload = {email}
export const signIn = async (payload) => {
Expand All @@ -15,7 +20,7 @@ export const signInPassword = async (payload) => {
const req = await fetch(`${API_HOST}/loginpassword`, {
...DEFAULT_POST,
body: JSON.stringify(payload),
}).then(checkRequest);
}).then(checkSeeOther);
const data = await req.json();
return data.link;
};
Expand Down
12 changes: 10 additions & 2 deletions src/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export const DEFAULT_PUT = {
credentials: 'include',
};

export class CustomError extends Error {
export class CustomError extends Error {
response;

constructor(message, response){
constructor(message, response) {
super(message);
this.response = response;
}
Expand All @@ -43,3 +43,11 @@ export const checkRequest = (res) => {

throw new CustomError(res.statusText, res);
};
export const checkSeeOther = (res) => {
if (res.status === 303) {
// res.status >= 200 && res.status < 300
return res;
}

throw new CustomError(res.statusText, res);
};

0 comments on commit c75b108

Please sign in to comment.