I want to check that the api is giving me the 500 status code back. But it does not work like below.
it('Check get licenseplace - incorrect license plate', () => {
cy.api({ url: '/api/autoverzekering/voertuiggegevens/get?kenteken=60-TX&voertuigtype=1' }, 'Test get voertuig gegevens - incorrect license plate').then(response => {
expect(response.status).to.eq(500);
});
});
CypressError: cy.request() failed on:
https://www.independer.nl/api/autoverzekering/voertuiggegevens/get?kenteken=60-TX&voertuigtype=1
The response we received from your web server was:
> 500: Server Error
This was considered a failure because the status code was not '2xx' or '3xx'.
If you do not want status codes to cause failures pass the option: 'failOnStatusCode: false'
-----------------------------------------------------------
The request we sent was:
Method: GET
URL: https://www.independer.nl/api/autoverzekering/voertuiggegevens/get?kenteken=60-TX&voertuigtype=1
Headers: {
"Connection": "keep-alive",
"user-agent": "Cypress/2.1.0 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
"accept": "*/*",
"cookie": "Independer.Cookies.CookieUserAuthorisation=permission=1&write-url=/api/cookieauthorisation/setcookiepermission; SSSCZ=10000=10000_0",
"accept-encoding": "gzip, deflate"
}
-----------------------------------------------------------
The response we got was:
Status: 500 - Server Error
Headers: {
"cache-control": "no-cache",
"pragma": "no-cache",
"content-type": "application/json; charset=utf-8",
"expires": "-1",
"server": "POWERED BY INDY",
"set-cookie": [
"ASP.NET_SessionId=coytc0305df42fmvriizvdyo; path=/; secure; HttpOnly; SameSite=Lax",
"StateID=64fd7b51-ef6e-4b89-b123-53549f5f76ea; expires=Fri, 07-Jan-2022 15:40:46 GMT; path=/; HttpOnly;Secure",
"Bron=Independer; path=/; HttpOnly;Secure"
],
"x-frame-options": "DENY",
"x-powered-by": "Hamsters",
"x-ua-compatible": "IE=edge,chrome=1",
"content-security-policy": "default-src https: wss: tel: 'self' 'unsafe-eval' 'unsafe-inline' data: blob:",
"p3p": "CP=\"NOI DSP COR CURa ADMa DEVa TAIa OUR BUS IND UNI COM NAV INT\"",
"referrer-policy": "origin",
"strict-transport-security": "max-age=31536000",
"x-content-type-options": "nosniff",
"x-xss-protection": "1;mode=block",
"content-security-policy-report-only": "default-src https: wss: 'self' 'unsafe-eval' 'unsafe-inline' data: blob:; report-uri https://92e06cc7ee8ab742c1100ba903663faa.report-uri.com/r/d/csp/reportOnly",
"date": "Tue, 07 Jan 2020 15:40:46 GMT",
"content-length": "5283"
}
Body: [
{
"key": "Message",
"value": "An error has occurred."
},
{
"key": "ExceptionMessage",
"value": "Service operation GetVoertuiggegevens failed due to validation errors: \r\n\r\n60-TX is not a valid kenteken. \r\n"
},
{
"key": "ExceptionType",
"value": "System.ServiceModel.FaultException"
},
{
"key": "StackTrace",
"value": " at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)\r\n at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass7_0`1.<CreateGenericTask>b__0(IAsyncResult asyncResult)\r\n at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at Independer.Site.Areas.Autoverzekering.Api.VoertuiggegevensController.<Get>d__0.MoveNext() in D:\\VsTsAgent\\_work\\475\\s\\Sites\\Independer.Site\\Areas\\Autoverzekering\\Api\\VoertuiggegevensController.cs:line 15\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__1`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()"
}
]