-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
Using Angular to create a SPA, it works fine as long as my API isn't responding with an error. Take for example this code:
try {
return User::findOrFail($user_id);
} catch (ModelNotFoundException $e) {
throw new ResourceException("No user record found.");
}If the user is found, Angular successfully retrieves the data. However if the record does not exist then this error is thrown.
XMLHttpRequest cannot load http://api.example.com/users/.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://my-angular-site.com' is therefore not allowed access.
Successful requests have these headers:
Access-Control-Allow-Origin →*
Cache-Control →no-cache, private
Connection →keep-alive
Content-Type →application/json
Server →nginx
Transfer-Encoding →chunked
X-Frame-Options →SAMEORIGIN
date →Fri, 23 May 2014 13:27:26 GMT
Responses provided by throwing an error have these headers:
Cache-Control →no-cache, private
Connection →keep-alive
Content-Type →application/json
Server →nginx
Transfer-Encoding →chunked
X-Frame-Options →SAMEORIGIN
date →Fri, 23 May 2014 13:31:29 GMT
UPDATE:
If I use the following code then returning the errors works.
try {
return User::findOrFail($user_id);
} catch (ModelNotFoundException $e) {
header('Access-Control-Allow-Origin: *');
throw new ResourceException("No user record found.");
}Metadata
Metadata
Assignees
Labels
No labels