Last active
September 27, 2018 14:58
-
-
Save lolmaus/a08016514e3f0464d005d1586cc2748b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Response from "ember-cli-mirage/response"; | |
import RouteHandler from "ember-cli-mirage/route-handler"; | |
import FunctionHandler from "ember-cli-mirage/route-handlers/function"; | |
import { MirageError } from "ember-cli-mirage/assert"; | |
// Workaround for https://github.com/samselikoff/ember-cli-mirage/issues/1386 | |
RouteHandler.prototype._getMirageResponseForRequest = function (request) { | |
let result; | |
try { | |
/* | |
We need to do this for the #serialize convenience method. Probably is | |
a better way. | |
*/ | |
if (this.handler instanceof FunctionHandler) { | |
this.handler.setRequest(request); | |
} | |
result = this.handler.handle(request); | |
} catch(e) { | |
if (e instanceof MirageError) { | |
throw e; | |
} else { | |
console.error(`Mirage ${request.method} handler for the url ${request.url} threw an error:\n\n${e.stack || e}`); // eslint-disable-line no-console | |
result = new Response(500, {}, e.message || e); | |
} | |
} | |
return this._toMirageResponse(result); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment