diff --git a/app/store/api.ts b/app/store/api.ts index f364f649..64d04f1c 100644 --- a/app/store/api.ts +++ b/app/store/api.ts @@ -56,6 +56,18 @@ interface ApiQuery { [key: string]: string } +interface ApiError { + code: number + message?: string +} + +export interface ApiResponseAction { + type: string + payload: { + [key: string]: any + } +} + // ApiActionThunk is the return value of an Api action. // All api actions must return a promise that will be called with their result: // either a SUCCESS or FAILURE action. This allows callers to chain @@ -98,7 +110,8 @@ async function getJSON (url: string, options: FetchOptions): Promise { const r = await fetch(url, options) const res = await r.json() if (res.meta.code !== 200) { - throw new Error(mapError(res.meta.error)) + var err: ApiError = { code: res.meta.code, message: mapError(res.meta.error) } + throw err // eslint-disable-line } return res as T } diff --git a/app/store/mapError.ts b/app/store/mapError.ts index 090511aa..ba1be9d3 100644 --- a/app/store/mapError.ts +++ b/app/store/mapError.ts @@ -10,7 +10,7 @@ const errors: {[key: string]: string} = { export default function mapError (err: string): string { var errMessage = err - if (err.includes('@')) { + if (err && err.includes('@')) { const start = err.indexOf('@') const errSlice = err.slice(start) const end = errSlice.indexOf(' ') + start