Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
ThaliApp
Commits
99cee02f
Commit
99cee02f
authored
Oct 22, 2017
by
Sébastiaan Versteeg
Committed by
Sébastiaan Versteeg
Feb 21, 2018
Browse files
Add language to every apiRequest
parent
098d30d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/url.js
View file @
99cee02f
import
locale
from
'
react-native-locale-detector
'
let
server
=
'
https://thalia.nu
'
;
/* istanbul ignore next line */
if
(
__DEV__
)
{
// eslint-disable-line no-undef
...
...
@@ -19,13 +21,17 @@ export class ServerError extends Error {
}
export
const
apiRequest
=
(
route
,
fetchOpts
,
params
)
=>
{
const
requestOptions
=
fetchOpts
;
requestOptions
.
headers
[
'
Accept-Language
'
]
=
locale
;
let
query
=
''
;
if
(
params
!==
null
&&
params
===
Object
(
params
))
{
query
=
`?
${
Object
.
keys
(
params
)
.
map
(
k
=>
`
${
encodeURIComponent
(
k
)}
=
${
encodeURIComponent
(
params
[
k
])}
`
)
.
join
(
'
&
'
)}
`
;
}
return
fetch
(
`
${
apiUrl
}
/
${
route
}
/
${
query
}
`
,
fetchOpts
)
return
fetch
(
`
${
apiUrl
}
/
${
route
}
/
${
query
}
`
,
requestOptions
)
.
then
((
response
)
=>
{
if
(
response
.
status
>=
400
&&
response
.
status
<=
500
)
{
throw
new
ServerError
(
`Invalid status code:
${
response
.
status
}
`
,
response
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment